2019-01-15 01:28:00 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2020-04-19 08:03:50 +00:00
|
|
|
"encoding/base64"
|
2020-03-04 10:29:00 +00:00
|
|
|
"encoding/json"
|
2019-01-15 01:28:00 +00:00
|
|
|
"fmt"
|
2020-03-08 18:13:27 +00:00
|
|
|
"github.com/getsentry/sentry-go"
|
2020-03-04 10:29:00 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-03-09 18:17:55 +00:00
|
|
|
_ "github.com/statping/statping/notifiers"
|
|
|
|
"github.com/statping/statping/source"
|
2020-03-19 01:50:53 +00:00
|
|
|
"github.com/statping/statping/types"
|
2020-03-09 18:17:55 +00:00
|
|
|
"github.com/statping/statping/types/core"
|
|
|
|
"github.com/statping/statping/types/groups"
|
|
|
|
"github.com/statping/statping/types/services"
|
|
|
|
"github.com/statping/statping/types/users"
|
|
|
|
"github.com/statping/statping/utils"
|
2019-01-15 01:28:00 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2020-06-09 00:51:37 +00:00
|
|
|
"time"
|
2019-01-15 01:28:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
dir string
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
utils.InitLogs()
|
2020-06-09 00:51:37 +00:00
|
|
|
source.Assets()
|
2019-01-15 01:28:00 +00:00
|
|
|
dir = utils.Directory
|
2020-03-22 07:57:17 +00:00
|
|
|
core.New("test")
|
2019-01-15 01:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFailedHTTPServer(t *testing.T) {
|
2020-06-09 00:51:37 +00:00
|
|
|
var err error
|
|
|
|
go func(err error) {
|
|
|
|
err = RunHTTPServer()
|
|
|
|
}(err)
|
|
|
|
go func() {
|
|
|
|
time.Sleep(3 * time.Second)
|
|
|
|
StopHTTPServer(nil)
|
|
|
|
}()
|
|
|
|
assert.Nil(t, err)
|
2019-01-15 01:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetupRoutes(t *testing.T) {
|
|
|
|
form := url.Values{}
|
2020-04-16 09:57:00 +00:00
|
|
|
form.Add("db_host", utils.Params.GetString("DB_HOST"))
|
|
|
|
form.Add("db_user", utils.Params.GetString("DB_USER"))
|
|
|
|
form.Add("db_password", utils.Params.GetString("DB_PASS"))
|
|
|
|
form.Add("db_database", utils.Params.GetString("DB_DATABASE"))
|
|
|
|
form.Add("db_connection", utils.Params.GetString("DB_CONN"))
|
|
|
|
form.Add("db_port", utils.Params.GetString("DB_PORT"))
|
2019-01-15 01:28:00 +00:00
|
|
|
form.Add("project", "Tester")
|
|
|
|
form.Add("username", "admin")
|
|
|
|
form.Add("password", "password123")
|
|
|
|
form.Add("sample_data", "on")
|
|
|
|
form.Add("description", "This is an awesome test")
|
|
|
|
form.Add("domain", "http://localhost:8080")
|
|
|
|
form.Add("email", "info@statping.com")
|
|
|
|
|
2020-04-19 08:03:50 +00:00
|
|
|
badForm := url.Values{}
|
|
|
|
badForm.Add("db_host", "badconnection")
|
|
|
|
badForm.Add("db_user", utils.Params.GetString("DB_USER"))
|
|
|
|
badForm.Add("db_password", utils.Params.GetString("DB_PASS"))
|
|
|
|
badForm.Add("db_database", utils.Params.GetString("DB_DATABASE"))
|
|
|
|
badForm.Add("db_connection", "mysql")
|
|
|
|
badForm.Add("db_port", utils.Params.GetString("DB_PORT"))
|
|
|
|
badForm.Add("project", "Tester")
|
|
|
|
badForm.Add("username", "admin")
|
|
|
|
badForm.Add("password", "password123")
|
|
|
|
badForm.Add("sample_data", "on")
|
|
|
|
badForm.Add("description", "This is an awesome test")
|
|
|
|
badForm.Add("domain", "http://localhost:8080")
|
|
|
|
badForm.Add("email", "info@statping.com")
|
|
|
|
|
2019-01-15 01:28:00 +00:00
|
|
|
tests := []HTTPTest{
|
|
|
|
{
|
2020-02-19 04:07:22 +00:00
|
|
|
Name: "Statping Check",
|
|
|
|
URL: "/api",
|
2019-01-15 01:28:00 +00:00
|
|
|
Method: "GET",
|
2020-02-19 04:07:22 +00:00
|
|
|
ExpectedStatus: 200,
|
2020-03-19 01:50:53 +00:00
|
|
|
FuncTest: func(t *testing.T) error {
|
2020-03-04 14:20:47 +00:00
|
|
|
if core.App.Setup {
|
2020-03-04 10:29:00 +00:00
|
|
|
return errors.New("core has already been setup")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
2019-01-15 01:28:00 +00:00
|
|
|
},
|
|
|
|
{
|
2020-04-19 08:03:50 +00:00
|
|
|
Name: "Statping Error Setup",
|
|
|
|
URL: "/api/setup",
|
|
|
|
Method: "POST",
|
|
|
|
Body: badForm.Encode(),
|
|
|
|
ExpectedStatus: 500,
|
|
|
|
ExpectedContains: []string{BadJSONDatabase},
|
|
|
|
HttpHeaders: []string{"Content-Type=application/x-www-form-urlencoded"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Statping Run Setup",
|
|
|
|
URL: "/api/setup",
|
|
|
|
Method: "POST",
|
|
|
|
Body: form.Encode(),
|
|
|
|
//ExpectedStatus: 200,
|
|
|
|
HttpHeaders: []string{"Content-Type=application/x-www-form-urlencoded"},
|
|
|
|
ExpectedFiles: []string{utils.Directory + "/config.yml"},
|
2020-03-19 01:50:53 +00:00
|
|
|
FuncTest: func(t *testing.T) error {
|
2020-03-04 14:20:47 +00:00
|
|
|
if !core.App.Setup {
|
2020-03-04 10:29:00 +00:00
|
|
|
return errors.New("core has not been setup")
|
|
|
|
}
|
2020-07-31 18:40:47 +00:00
|
|
|
if core.App.ApiSecret == "" {
|
|
|
|
return errors.New("API Key has not been set")
|
|
|
|
}
|
2020-03-08 01:23:41 +00:00
|
|
|
if len(services.AllInOrder()) == 0 {
|
|
|
|
return errors.New("no services where found")
|
|
|
|
}
|
|
|
|
if len(users.All()) == 0 {
|
|
|
|
return errors.New("no users where found")
|
|
|
|
}
|
|
|
|
if len(groups.All()) == 0 {
|
|
|
|
return errors.New("no groups where found")
|
|
|
|
}
|
2020-03-04 10:29:00 +00:00
|
|
|
return nil
|
|
|
|
},
|
2020-03-13 04:06:06 +00:00
|
|
|
AfterTest: StopServices,
|
2020-04-19 08:03:50 +00:00
|
|
|
},
|
|
|
|
}
|
2019-01-15 01:28:00 +00:00
|
|
|
|
|
|
|
for _, v := range tests {
|
|
|
|
t.Run(v.Name, func(t *testing.T) {
|
2019-01-29 12:58:25 +00:00
|
|
|
_, t, err := RunHTTPTest(v, t)
|
2019-01-15 01:28:00 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
if err != nil {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMainApiRoutes(t *testing.T) {
|
2020-04-17 03:21:17 +00:00
|
|
|
date := utils.Now().Format("2006-01")
|
2019-01-15 01:28:00 +00:00
|
|
|
tests := []HTTPTest{
|
|
|
|
{
|
|
|
|
Name: "Statping Details",
|
|
|
|
URL: "/api",
|
|
|
|
Method: "GET",
|
|
|
|
ExpectedStatus: 200,
|
2020-03-31 20:38:43 +00:00
|
|
|
ExpectedContains: []string{`"description":"This is an awesome test"`},
|
2020-03-19 01:50:53 +00:00
|
|
|
FuncTest: func(t *testing.T) error {
|
2020-03-04 14:20:47 +00:00
|
|
|
if !core.App.Setup {
|
2020-03-04 10:29:00 +00:00
|
|
|
return errors.New("database is not setup")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
2019-02-06 18:51:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Statping Renew API Keys",
|
|
|
|
URL: "/api/renew",
|
|
|
|
Method: "POST",
|
2020-02-19 04:07:22 +00:00
|
|
|
ExpectedStatus: 200,
|
2020-03-08 01:23:41 +00:00
|
|
|
BeforeTest: SetTestENV,
|
|
|
|
SecureRoute: true,
|
2019-02-06 18:51:30 +00:00
|
|
|
},
|
2020-04-16 17:32:54 +00:00
|
|
|
{
|
|
|
|
Name: "Statping View Cache",
|
|
|
|
URL: "/api/cache",
|
|
|
|
Method: "GET",
|
|
|
|
ExpectedStatus: 200,
|
|
|
|
BeforeTest: SetTestENV,
|
|
|
|
SecureRoute: true,
|
|
|
|
ResponseLen: 0,
|
|
|
|
},
|
2019-02-06 18:51:30 +00:00
|
|
|
{
|
|
|
|
Name: "Statping Clear Cache",
|
|
|
|
URL: "/api/clear_cache",
|
|
|
|
Method: "POST",
|
2020-02-19 04:07:22 +00:00
|
|
|
ExpectedStatus: 200,
|
2020-03-19 01:50:53 +00:00
|
|
|
SecureRoute: true,
|
|
|
|
BeforeTest: func(t *testing.T) error {
|
|
|
|
CacheStorage.Set("test", []byte("data here"), types.Day)
|
|
|
|
list := CacheStorage.List()
|
|
|
|
assert.Len(t, list, 1)
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
AfterTest: func(t *testing.T) error {
|
|
|
|
list := CacheStorage.List()
|
|
|
|
assert.Len(t, list, 0)
|
2020-03-04 10:29:00 +00:00
|
|
|
return nil
|
|
|
|
},
|
2019-03-05 20:13:25 +00:00
|
|
|
},
|
2020-03-19 04:55:32 +00:00
|
|
|
{
|
|
|
|
Name: "Update Core",
|
|
|
|
URL: "/api/core",
|
|
|
|
Method: "POST",
|
|
|
|
ExpectedStatus: 200,
|
|
|
|
Body: `{
|
|
|
|
"name": "Updated Core"
|
|
|
|
}`,
|
|
|
|
AfterTest: func(t *testing.T) error {
|
|
|
|
assert.Equal(t, "Updated Core", core.App.Name)
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2019-03-05 20:13:25 +00:00
|
|
|
{
|
|
|
|
Name: "404 Error Page",
|
|
|
|
URL: "/api/missing_404_page",
|
|
|
|
Method: "GET",
|
|
|
|
ExpectedStatus: 404,
|
2020-03-19 04:55:32 +00:00
|
|
|
},
|
2020-04-16 17:32:54 +00:00
|
|
|
{
|
|
|
|
Name: "Health Check endpoint",
|
|
|
|
URL: "/health",
|
|
|
|
Method: "GET",
|
|
|
|
ExpectedStatus: 200,
|
|
|
|
ExpectedContains: []string{`"online":true`, `"setup":true`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Logs endpoint",
|
|
|
|
URL: "/api/logs",
|
|
|
|
Method: "GET",
|
|
|
|
ExpectedStatus: 200,
|
2020-04-16 20:53:52 +00:00
|
|
|
GreaterThan: 20,
|
2020-04-16 17:32:54 +00:00
|
|
|
ExpectedContains: []string{date},
|
|
|
|
},
|
2020-04-19 08:03:50 +00:00
|
|
|
{
|
|
|
|
Name: "Logs endpoint",
|
|
|
|
URL: "/api/logs",
|
|
|
|
Method: "GET",
|
|
|
|
ExpectedStatus: 200,
|
|
|
|
GreaterThan: 20,
|
|
|
|
ExpectedContains: []string{date},
|
|
|
|
},
|
2020-04-16 17:32:54 +00:00
|
|
|
{
|
|
|
|
Name: "Logs Last Line endpoint",
|
|
|
|
URL: "/api/logs/last",
|
|
|
|
Method: "GET",
|
|
|
|
ExpectedStatus: 200,
|
|
|
|
ExpectedContains: []string{date},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Prometheus Export Metrics",
|
|
|
|
URL: "/metrics",
|
|
|
|
Method: "GET",
|
|
|
|
BeforeTest: SetTestENV,
|
2020-05-14 03:09:32 +00:00
|
|
|
AfterTest: UnsetTestENV,
|
2020-04-16 17:32:54 +00:00
|
|
|
ExpectedStatus: 200,
|
|
|
|
ExpectedContains: []string{
|
2020-06-13 04:12:31 +00:00
|
|
|
`go_goroutines`,
|
|
|
|
`go_memstats_alloc_bytes`,
|
2020-06-16 14:48:08 +00:00
|
|
|
`go_threads`,
|
2020-04-16 17:32:54 +00:00
|
|
|
},
|
|
|
|
},
|
2020-07-20 11:58:13 +00:00
|
|
|
{
|
|
|
|
Name: "Index Page",
|
|
|
|
URL: "/",
|
|
|
|
Method: "GET",
|
|
|
|
ExpectedStatus: 200,
|
|
|
|
},
|
2020-03-19 04:55:32 +00:00
|
|
|
}
|
2019-01-15 01:28:00 +00:00
|
|
|
|
|
|
|
for _, v := range tests {
|
|
|
|
t.Run(v.Name, func(t *testing.T) {
|
2020-03-08 01:23:41 +00:00
|
|
|
res, t, err := RunHTTPTest(v, t)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
t.Log(res)
|
2019-01-15 01:28:00 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 01:50:53 +00:00
|
|
|
type HttpFuncTest func(*testing.T) error
|
2019-01-15 01:28:00 +00:00
|
|
|
|
2020-07-04 19:18:56 +00:00
|
|
|
type ResponseFunc func(*httptest.ResponseRecorder, *testing.T, []byte) error
|
2020-04-16 17:32:54 +00:00
|
|
|
|
2019-01-15 01:28:00 +00:00
|
|
|
// HTTPTest contains all the parameters for a HTTP Unit Test
|
|
|
|
type HTTPTest struct {
|
2020-03-19 01:50:53 +00:00
|
|
|
Name string
|
|
|
|
URL string
|
|
|
|
Method string
|
|
|
|
Body string
|
|
|
|
ExpectedStatus int
|
|
|
|
ExpectedContains []string
|
|
|
|
ExpectedNotContains []string
|
|
|
|
HttpHeaders []string
|
|
|
|
ExpectedFiles []string
|
|
|
|
FuncTest HttpFuncTest
|
|
|
|
BeforeTest HttpFuncTest
|
|
|
|
AfterTest HttpFuncTest
|
2020-04-16 17:32:54 +00:00
|
|
|
ResponseFunc ResponseFunc
|
2020-03-19 01:50:53 +00:00
|
|
|
ResponseLen int
|
2020-04-16 17:32:54 +00:00
|
|
|
GreaterThan int
|
2020-03-19 01:50:53 +00:00
|
|
|
SecureRoute bool
|
2020-04-16 17:32:54 +00:00
|
|
|
Skip bool
|
2019-01-15 01:28:00 +00:00
|
|
|
}
|
|
|
|
|
2020-03-08 18:13:27 +00:00
|
|
|
func logTest(t *testing.T, err error) error {
|
|
|
|
e := sentry.NewEvent()
|
|
|
|
e.Environment = "testing"
|
|
|
|
e.Timestamp = utils.Now().Unix()
|
|
|
|
e.Message = fmt.Sprintf("failed test %s", t.Name())
|
|
|
|
e.Transaction = t.Name()
|
|
|
|
sentry.CaptureEvent(e)
|
|
|
|
sentry.CaptureException(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-01-15 01:28:00 +00:00
|
|
|
// RunHTTPTest accepts a HTTPTest type to execute the HTTP request
|
|
|
|
func RunHTTPTest(test HTTPTest, t *testing.T) (string, *testing.T, error) {
|
2020-04-16 17:32:54 +00:00
|
|
|
if test.Skip {
|
|
|
|
t.SkipNow()
|
|
|
|
}
|
2020-03-08 01:23:41 +00:00
|
|
|
if test.BeforeTest != nil {
|
2020-03-19 01:50:53 +00:00
|
|
|
if err := test.BeforeTest(t); err != nil {
|
2020-03-08 18:13:27 +00:00
|
|
|
return "", t, logTest(t, err)
|
2020-03-08 01:23:41 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-08 18:13:27 +00:00
|
|
|
|
|
|
|
rr, err := Request(test)
|
2019-01-15 01:28:00 +00:00
|
|
|
if err != nil {
|
2020-03-08 18:13:27 +00:00
|
|
|
return "", t, logTest(t, err)
|
2019-01-15 01:28:00 +00:00
|
|
|
}
|
2020-03-08 18:13:27 +00:00
|
|
|
defer rr.Result().Body.Close()
|
2019-12-30 00:40:20 +00:00
|
|
|
|
2020-04-19 08:03:50 +00:00
|
|
|
if test.ExpectedStatus != 0 {
|
|
|
|
if test.ExpectedStatus != rr.Result().StatusCode {
|
|
|
|
assert.Equal(t, test.ExpectedStatus, rr.Result().StatusCode)
|
|
|
|
return "", t, fmt.Errorf("status code %v does not match %v", rr.Result().StatusCode, test.ExpectedStatus)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 01:28:00 +00:00
|
|
|
body, err := ioutil.ReadAll(rr.Result().Body)
|
|
|
|
if err != nil {
|
|
|
|
assert.Nil(t, err)
|
2020-03-08 18:13:27 +00:00
|
|
|
return "", t, logTest(t, err)
|
2019-01-15 01:28:00 +00:00
|
|
|
}
|
2020-03-04 10:29:00 +00:00
|
|
|
|
2019-01-15 01:28:00 +00:00
|
|
|
stringBody := string(body)
|
2020-03-08 01:23:41 +00:00
|
|
|
|
2019-01-15 01:28:00 +00:00
|
|
|
if len(test.ExpectedContains) != 0 {
|
|
|
|
for _, v := range test.ExpectedContains {
|
|
|
|
assert.Contains(t, stringBody, v)
|
|
|
|
}
|
|
|
|
}
|
2020-03-19 01:50:53 +00:00
|
|
|
if len(test.ExpectedNotContains) != 0 {
|
|
|
|
for _, v := range test.ExpectedNotContains {
|
|
|
|
assert.NotContains(t, stringBody, v)
|
|
|
|
}
|
|
|
|
}
|
2019-01-15 01:28:00 +00:00
|
|
|
if len(test.ExpectedFiles) != 0 {
|
|
|
|
for _, v := range test.ExpectedFiles {
|
|
|
|
assert.FileExists(t, v)
|
|
|
|
}
|
|
|
|
}
|
2020-03-04 10:29:00 +00:00
|
|
|
if test.FuncTest != nil {
|
2020-03-19 01:50:53 +00:00
|
|
|
err := test.FuncTest(t)
|
2020-03-04 10:29:00 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
2020-04-16 17:32:54 +00:00
|
|
|
if test.ResponseFunc != nil {
|
2020-07-04 19:18:56 +00:00
|
|
|
err := test.ResponseFunc(rr, t, body)
|
2020-04-16 17:32:54 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
2020-03-04 10:29:00 +00:00
|
|
|
if test.ResponseLen != 0 {
|
|
|
|
var respArray []interface{}
|
|
|
|
err := json.Unmarshal(body, &respArray)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, test.ResponseLen, len(respArray))
|
|
|
|
}
|
2020-04-16 17:32:54 +00:00
|
|
|
|
|
|
|
if test.GreaterThan != 0 {
|
|
|
|
var respArray []interface{}
|
|
|
|
err := json.Unmarshal(body, &respArray)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.GreaterOrEqual(t, len(respArray), test.GreaterThan)
|
|
|
|
}
|
2020-03-08 18:13:27 +00:00
|
|
|
|
2020-03-08 01:23:41 +00:00
|
|
|
if test.AfterTest != nil {
|
2020-03-19 01:50:53 +00:00
|
|
|
if err := test.AfterTest(t); err != nil {
|
2020-03-08 18:13:27 +00:00
|
|
|
return "", t, logTest(t, err)
|
2020-03-08 01:23:41 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-08 18:13:27 +00:00
|
|
|
return stringBody, t, logTest(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Request(test HTTPTest) (*httptest.ResponseRecorder, error) {
|
2020-03-19 03:13:50 +00:00
|
|
|
req, err := http.NewRequest(test.Method, test.URL, strings.NewReader(test.Body))
|
2020-03-08 18:13:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(test.HttpHeaders) != 0 {
|
|
|
|
for _, v := range test.HttpHeaders {
|
|
|
|
splits := strings.Split(v, "=")
|
|
|
|
req.Header.Set(splits[0], splits[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rr := httptest.NewRecorder()
|
|
|
|
Router().ServeHTTP(rr, req)
|
|
|
|
return rr, err
|
2019-01-15 01:28:00 +00:00
|
|
|
}
|
2020-03-08 01:23:41 +00:00
|
|
|
|
2020-03-19 01:50:53 +00:00
|
|
|
func SetTestENV(t *testing.T) error {
|
2020-04-19 08:03:50 +00:00
|
|
|
utils.Params.Set("GO_ENV", "test")
|
|
|
|
return nil
|
2020-03-08 01:23:41 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 01:50:53 +00:00
|
|
|
func UnsetTestENV(t *testing.T) error {
|
2020-04-19 08:03:50 +00:00
|
|
|
utils.Params.Set("GO_ENV", "production")
|
|
|
|
return nil
|
2020-03-08 01:23:41 +00:00
|
|
|
}
|
2020-03-13 04:06:06 +00:00
|
|
|
|
2020-03-19 01:50:53 +00:00
|
|
|
func StopServices(t *testing.T) error {
|
2020-03-13 04:06:06 +00:00
|
|
|
for _, s := range services.All() {
|
|
|
|
s.Close()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2020-04-16 17:32:54 +00:00
|
|
|
|
2020-04-19 08:03:50 +00:00
|
|
|
func basicAuth(username, password string) string {
|
|
|
|
auth := username + ":" + password
|
|
|
|
return base64.StdEncoding.EncodeToString([]byte(auth))
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:32:54 +00:00
|
|
|
var (
|
|
|
|
Success = `"status":"success"`
|
2020-04-19 08:03:50 +00:00
|
|
|
|
|
|
|
MethodCreate = `"method":"create"`
|
|
|
|
MethodUpdate = `"method":"update"`
|
|
|
|
MethodDelete = `"method":"delete"`
|
|
|
|
|
|
|
|
BadJSON = `{incorrect: JSON %%% formatting, [&]}`
|
|
|
|
BadJSONResponse = `{"error":"could not decode incoming JSON"}`
|
|
|
|
BadJSONDatabase = `{"error":"error connecting to database`
|
2020-04-16 17:32:54 +00:00
|
|
|
)
|