mirror of https://github.com/statping/statping
updated CLI commands - code organization
parent
d8e34b397a
commit
0718b61e49
3
Makefile
3
Makefile
|
@ -1,4 +1,4 @@
|
||||||
VERSION=0.79.86
|
VERSION=0.79.87
|
||||||
BINARY_NAME=statup
|
BINARY_NAME=statup
|
||||||
GOPATH:=$(GOPATH)
|
GOPATH:=$(GOPATH)
|
||||||
GOCMD=go
|
GOCMD=go
|
||||||
|
@ -232,6 +232,7 @@ clean:
|
||||||
rm -rf dev/test/cypress/videos
|
rm -rf dev/test/cypress/videos
|
||||||
rm -f coverage.* sass
|
rm -f coverage.* sass
|
||||||
rm -f source/rice-box.go
|
rm -f source/rice-box.go
|
||||||
|
rm -f *.db-journal
|
||||||
find . -name "*.out" -type f -delete
|
find . -name "*.out" -type f -delete
|
||||||
find . -name "*.cpu" -type f -delete
|
find . -name "*.cpu" -type f -delete
|
||||||
find . -name "*.mem" -type f -delete
|
find . -name "*.mem" -type f -delete
|
||||||
|
|
49
cmd/cli.go
49
cmd/cli.go
|
@ -23,10 +23,12 @@ import (
|
||||||
"github.com/hunterlong/statup/handlers"
|
"github.com/hunterlong/statup/handlers"
|
||||||
"github.com/hunterlong/statup/plugin"
|
"github.com/hunterlong/statup/plugin"
|
||||||
"github.com/hunterlong/statup/source"
|
"github.com/hunterlong/statup/source"
|
||||||
|
"github.com/hunterlong/statup/types"
|
||||||
"github.com/hunterlong/statup/utils"
|
"github.com/hunterlong/statup/utils"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -85,13 +87,15 @@ func catchCLI(args []string) error {
|
||||||
case "export":
|
case "export":
|
||||||
var err error
|
var err error
|
||||||
fmt.Printf("Statup v%v Exporting Static 'index.html' page...\n", VERSION)
|
fmt.Printf("Statup v%v Exporting Static 'index.html' page...\n", VERSION)
|
||||||
|
utils.InitLogs()
|
||||||
core.Configs, err = core.LoadConfigFile(dir)
|
core.Configs, err = core.LoadConfigFile(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log(4, "config.yml file not found")
|
utils.Log(4, "config.yml file not found")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
indexSource := core.ExportIndexHTML()
|
indexSource := ExportIndexHTML()
|
||||||
err = utils.SaveFile("./index.html", []byte(indexSource))
|
core.CloseDB()
|
||||||
|
err = utils.SaveFile(dir+"/index.html", indexSource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log(4, err)
|
utils.Log(4, err)
|
||||||
return err
|
return err
|
||||||
|
@ -103,6 +107,7 @@ func catchCLI(args []string) error {
|
||||||
case "run":
|
case "run":
|
||||||
utils.Log(1, "Running 1 time and saving to database...")
|
utils.Log(1, "Running 1 time and saving to database...")
|
||||||
RunOnce()
|
RunOnce()
|
||||||
|
core.CloseDB()
|
||||||
fmt.Println("Check is complete.")
|
fmt.Println("Check is complete.")
|
||||||
return errors.New("end")
|
return errors.New("end")
|
||||||
case "env":
|
case "env":
|
||||||
|
@ -121,6 +126,22 @@ func catchCLI(args []string) error {
|
||||||
return errors.New("end")
|
return errors.New("end")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExportIndexHTML returns the HTML of the index page as a string
|
||||||
|
func ExportIndexHTML() []byte {
|
||||||
|
source.Assets()
|
||||||
|
core.Configs.Connect(false, utils.Directory)
|
||||||
|
core.CoreApp.SelectAllServices(false)
|
||||||
|
core.CoreApp.UseCdn = types.NewNullBool(true)
|
||||||
|
for _, srv := range core.CoreApp.Services {
|
||||||
|
service := srv.(*core.Service)
|
||||||
|
service.Check(true)
|
||||||
|
}
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
r := httptest.NewRequest("GET", "/", nil)
|
||||||
|
handlers.ExecuteResponse(w, r, "index.html", nil, nil)
|
||||||
|
return w.Body.Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
// RunOnce will initialize the Statup application and check each service 1 time, will not run HTTP server
|
// RunOnce will initialize the Statup application and check each service 1 time, will not run HTTP server
|
||||||
func RunOnce() {
|
func RunOnce() {
|
||||||
var err error
|
var err error
|
||||||
|
@ -141,9 +162,7 @@ func RunOnce() {
|
||||||
utils.Log(4, err)
|
utils.Log(4, err)
|
||||||
}
|
}
|
||||||
for _, out := range core.CoreApp.Services {
|
for _, out := range core.CoreApp.Services {
|
||||||
service := out.Select()
|
|
||||||
out.Check(true)
|
out.Check(true)
|
||||||
fmt.Printf(" Service %v | URL: %v | Latency: %0.0fms | Online: %v\n", service.Name, service.Domain, (service.Latency * 1000), service.Online)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,16 +174,32 @@ func HelpEcho() {
|
||||||
fmt.Println(" statup - Main command to run Statup server")
|
fmt.Println(" statup - Main command to run Statup server")
|
||||||
fmt.Println(" statup version - Returns the current version of Statup")
|
fmt.Println(" statup version - Returns the current version of Statup")
|
||||||
fmt.Println(" statup run - Check all services 1 time and then quit")
|
fmt.Println(" statup run - Check all services 1 time and then quit")
|
||||||
fmt.Println(" statup test plugins - Test all plugins for required information")
|
|
||||||
fmt.Println(" statup assets - Dump all assets used locally to be edited.")
|
fmt.Println(" statup assets - Dump all assets used locally to be edited.")
|
||||||
fmt.Println(" statup sass - Compile .scss files into the css directory")
|
|
||||||
fmt.Println(" statup env - Show all environment variables being used for Statup")
|
|
||||||
fmt.Println(" statup export - Exports the index page as a static HTML for pushing")
|
fmt.Println(" statup export - Exports the index page as a static HTML for pushing")
|
||||||
|
fmt.Println(" statup sass - Compile .scss files into the css directory")
|
||||||
|
fmt.Println(" statup test plugins - Test all plugins for required information")
|
||||||
|
fmt.Println(" statup env - Show all environment variables being used for Statup")
|
||||||
fmt.Println(" statup update - Attempts to update to the latest version")
|
fmt.Println(" statup update - Attempts to update to the latest version")
|
||||||
fmt.Println(" statup help - Shows the user basic information about Statup")
|
fmt.Println(" statup help - Shows the user basic information about Statup")
|
||||||
fmt.Printf("Flags:\n")
|
fmt.Printf("Flags:\n")
|
||||||
fmt.Println(" -ip 127.0.0.1 - Run HTTP server on specific IP address (default: localhost)")
|
fmt.Println(" -ip 127.0.0.1 - Run HTTP server on specific IP address (default: localhost)")
|
||||||
fmt.Println(" -port 8080 - Run HTTP server on Port (default: 8080)")
|
fmt.Println(" -port 8080 - Run HTTP server on Port (default: 8080)")
|
||||||
|
fmt.Printf("Environment Variables:\n")
|
||||||
|
fmt.Println(" STATUP_DIR - Set a absolute path for the root path of Statup server (logs, assets, SQL db)")
|
||||||
|
fmt.Println(" DB_CONN - Automatic Database connection (sqlite, postgres, mysql)")
|
||||||
|
fmt.Println(" DB_HOST - Database hostname or IP address")
|
||||||
|
fmt.Println(" DB_USER - Database username")
|
||||||
|
fmt.Println(" DB_PASS - Database password")
|
||||||
|
fmt.Println(" DB_PORT - Database port (5432, 3306, ...")
|
||||||
|
fmt.Println(" DB_DATABASE - Database connection's database name")
|
||||||
|
fmt.Println(" GO_ENV - Run Statup in testmode, will bypass HTTP authentication (if set as 'true')")
|
||||||
|
fmt.Println(" NAME - Set a name for the Statup status page")
|
||||||
|
fmt.Println(" DESCRIPTION - Set a description for the Statup status page")
|
||||||
|
fmt.Println(" DOMAIN - Set a URL for the Statup status page")
|
||||||
|
fmt.Println(" ADMIN_USER - Username for administrator account (default: admin)")
|
||||||
|
fmt.Println(" ADMIN_PASS - Password for administrator account (default: admin)")
|
||||||
|
fmt.Println(" * You can insert environment variables into a '.env' file in root directory.")
|
||||||
|
|
||||||
fmt.Println("Give Statup a Star at https://github.com/hunterlong/statup")
|
fmt.Println("Give Statup a Star at https://github.com/hunterlong/statup")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,20 +16,35 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/hunterlong/statup/core"
|
||||||
|
"github.com/hunterlong/statup/utils"
|
||||||
"github.com/rendon/testcli"
|
"github.com/rendon/testcli"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRunSQLiteApp(t *testing.T) {
|
var (
|
||||||
t.SkipNow()
|
dir string
|
||||||
run := catchCLI([]string{"app"})
|
)
|
||||||
assert.Nil(t, run)
|
|
||||||
|
func init() {
|
||||||
|
dir = utils.Directory
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfirmVersion(t *testing.T) {
|
func TestStartServerCommand(t *testing.T) {
|
||||||
t.SkipNow()
|
Clean()
|
||||||
assert.NotEmpty(t, VERSION)
|
os.Setenv("DB_CONN", "sqlite")
|
||||||
|
cmd := helperCommand(nil, "")
|
||||||
|
var got = make(chan string)
|
||||||
|
commandAndSleep(cmd, time.Duration(8*time.Second), got)
|
||||||
|
os.Unsetenv("DB_CONN")
|
||||||
|
gg, _ := <-got
|
||||||
|
assert.Contains(t, gg, "DB_CONN environment variable was found")
|
||||||
|
assert.Contains(t, gg, "Core database does not exist, creating now!")
|
||||||
|
assert.Contains(t, gg, "Starting monitoring process for 5 Services")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVersionCommand(t *testing.T) {
|
func TestVersionCommand(t *testing.T) {
|
||||||
|
@ -46,14 +61,23 @@ func TestHelpCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExportCommand(t *testing.T) {
|
func TestExportCommand(t *testing.T) {
|
||||||
t.SkipNow()
|
cmd := helperCommand(nil, "export")
|
||||||
c := testcli.Command("statup", "export")
|
var got = make(chan string)
|
||||||
c.Run()
|
commandAndSleep(cmd, time.Duration(4*time.Second), got)
|
||||||
t.Log(c.Stdout())
|
gg, _ := <-got
|
||||||
assert.True(t, c.StdoutContains("Exporting Static 'index.html' page"))
|
t.Log(gg)
|
||||||
|
assert.Contains(t, gg, "Exporting Static 'index.html' page...")
|
||||||
|
assert.Contains(t, gg, "Exported Statup index page: 'index.html'")
|
||||||
assert.True(t, fileExists(dir+"/index.html"))
|
assert.True(t, fileExists(dir+"/index.html"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUpdateCommand(t *testing.T) {
|
||||||
|
c := testcli.Command("statup", "update")
|
||||||
|
c.Run()
|
||||||
|
assert.True(t, c.StdoutContains("Statup Version: "+VERSION))
|
||||||
|
assert.True(t, c.StdoutContains("Latest Version:"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestAssetsCommand(t *testing.T) {
|
func TestAssetsCommand(t *testing.T) {
|
||||||
c := testcli.Command("statup", "assets")
|
c := testcli.Command("statup", "assets")
|
||||||
c.Run()
|
c.Run()
|
||||||
|
@ -63,6 +87,22 @@ func TestAssetsCommand(t *testing.T) {
|
||||||
assert.FileExists(t, dir+"/assets/scss/base.scss")
|
assert.FileExists(t, dir+"/assets/scss/base.scss")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunCommand(t *testing.T) {
|
||||||
|
cmd := helperCommand(nil, "run")
|
||||||
|
var got = make(chan string)
|
||||||
|
commandAndSleep(cmd, time.Duration(5*time.Second), got)
|
||||||
|
gg, _ := <-got
|
||||||
|
t.Log(gg)
|
||||||
|
assert.Contains(t, gg, "Running 1 time and saving to database...")
|
||||||
|
assert.Contains(t, gg, "Check is complete.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEnvironmentVarsCommand(t *testing.T) {
|
||||||
|
c := testcli.Command("statup", "env")
|
||||||
|
c.Run()
|
||||||
|
assert.True(t, c.StdoutContains("Statup Environment Variable"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestVersionCLI(t *testing.T) {
|
func TestVersionCLI(t *testing.T) {
|
||||||
run := catchCLI([]string{"version"})
|
run := catchCLI([]string{"version"})
|
||||||
assert.EqualError(t, run, "end")
|
assert.EqualError(t, run, "end")
|
||||||
|
@ -82,7 +122,6 @@ func TestSassCLI(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateCLI(t *testing.T) {
|
func TestUpdateCLI(t *testing.T) {
|
||||||
t.SkipNow()
|
|
||||||
run := catchCLI([]string{"update"})
|
run := catchCLI([]string{"update"})
|
||||||
assert.EqualError(t, run, "end")
|
assert.EqualError(t, run, "end")
|
||||||
}
|
}
|
||||||
|
@ -100,10 +139,30 @@ func TestHelpCLI(t *testing.T) {
|
||||||
func TestRunOnceCLI(t *testing.T) {
|
func TestRunOnceCLI(t *testing.T) {
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
run := catchCLI([]string{"run"})
|
run := catchCLI([]string{"run"})
|
||||||
assert.Nil(t, run)
|
assert.EqualError(t, run, "end")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnvCLI(t *testing.T) {
|
func TestEnvCLI(t *testing.T) {
|
||||||
run := catchCLI([]string{"env"})
|
run := catchCLI([]string{"env"})
|
||||||
assert.Error(t, run)
|
assert.Error(t, run)
|
||||||
|
core.CloseDB()
|
||||||
|
Clean()
|
||||||
|
}
|
||||||
|
|
||||||
|
func commandAndSleep(cmd *exec.Cmd, duration time.Duration, out chan<- string) {
|
||||||
|
go func(out chan<- string) {
|
||||||
|
runCommand(cmd, out)
|
||||||
|
}(out)
|
||||||
|
time.Sleep(duration)
|
||||||
|
cmd.Process.Kill()
|
||||||
|
}
|
||||||
|
|
||||||
|
func helperCommand(envs []string, s ...string) *exec.Cmd {
|
||||||
|
cmd := exec.Command("statup", s...)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func runCommand(c *exec.Cmd, out chan<- string) {
|
||||||
|
bout, _ := c.CombinedOutput()
|
||||||
|
out <- string(bout)
|
||||||
}
|
}
|
||||||
|
|
14
cmd/main.go
14
cmd/main.go
|
@ -26,6 +26,7 @@ import (
|
||||||
"github.com/hunterlong/statup/utils"
|
"github.com/hunterlong/statup/utils"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -73,14 +74,23 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
utils.Log(1, fmt.Sprintf("Starting Statup v%v", VERSION))
|
utils.Log(1, fmt.Sprintf("Starting Statup v%v", VERSION))
|
||||||
|
defer core.CloseDB()
|
||||||
|
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt)
|
||||||
|
go func() {
|
||||||
|
<-c
|
||||||
|
core.CloseDB()
|
||||||
|
os.Exit(1)
|
||||||
|
}()
|
||||||
|
|
||||||
core.Configs, err = core.LoadConfigFile(utils.Directory)
|
core.Configs, err = core.LoadConfigFile(utils.Directory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log(3, err)
|
utils.Log(3, err)
|
||||||
core.SetupMode = true
|
core.SetupMode = true
|
||||||
fmt.Println(handlers.RunHTTPServer(ipAddress, port))
|
utils.Log(1, handlers.RunHTTPServer(ipAddress, port))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer core.CloseDB()
|
|
||||||
mainProcess()
|
mainProcess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
route *mux.Router
|
route *mux.Router
|
||||||
dir string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -50,6 +49,7 @@ func Clean() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunInit(db string, t *testing.T) {
|
func RunInit(db string, t *testing.T) {
|
||||||
|
Clean()
|
||||||
if db == "mssql" {
|
if db == "mssql" {
|
||||||
os.Setenv("DB_DATABASE", "tempdb")
|
os.Setenv("DB_DATABASE", "tempdb")
|
||||||
os.Setenv("DB_PASS", "PaSsW0rD123")
|
os.Setenv("DB_PASS", "PaSsW0rD123")
|
||||||
|
@ -57,19 +57,18 @@ func RunInit(db string, t *testing.T) {
|
||||||
os.Setenv("DB_USER", "sa")
|
os.Setenv("DB_USER", "sa")
|
||||||
}
|
}
|
||||||
source.Assets()
|
source.Assets()
|
||||||
Clean()
|
|
||||||
route = handlers.Router()
|
route = handlers.Router()
|
||||||
core.CoreApp = core.NewCore()
|
core.CoreApp = core.NewCore()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
//func TestMain(m *testing.M) {
|
||||||
m.Run()
|
// m.Run()
|
||||||
}
|
//}
|
||||||
|
|
||||||
func TestRunAll(t *testing.T) {
|
func TestRunAll(t *testing.T) {
|
||||||
//t.Parallel()
|
//t.Parallel()
|
||||||
|
|
||||||
databases := []string{"postgres", "sqlite", "mysql"}
|
databases := []string{"sqlite", "postgres", "mysql"}
|
||||||
if os.Getenv("ONLY_DB") != "" {
|
if os.Getenv("ONLY_DB") != "" {
|
||||||
databases = []string{os.Getenv("ONLY_DB")}
|
databases = []string{os.Getenv("ONLY_DB")}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ func DefaultPort(db string) int64 {
|
||||||
|
|
||||||
// EnvToConfig converts environment variables to a DbConfig variable
|
// EnvToConfig converts environment variables to a DbConfig variable
|
||||||
func EnvToConfig() *DbConfig {
|
func EnvToConfig() *DbConfig {
|
||||||
port := utils.StringInt(os.Getenv("DB_PORT"))
|
port := utils.ToInt(os.Getenv("DB_PORT"))
|
||||||
if port == 0 {
|
if port == 0 {
|
||||||
port = DefaultPort(os.Getenv("DB_PORT"))
|
port = DefaultPort(os.Getenv("DB_PORT"))
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,17 @@ func EnvToConfig() *DbConfig {
|
||||||
if description == "" {
|
if description == "" {
|
||||||
description = "Statup Monitoring Sample Data"
|
description = "Statup Monitoring Sample Data"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adminUser := os.Getenv("ADMIN_USER")
|
||||||
|
if adminUser == "" {
|
||||||
|
adminUser = "admin"
|
||||||
|
}
|
||||||
|
|
||||||
|
adminPass := os.Getenv("ADMIN_PASS")
|
||||||
|
if adminPass == "" {
|
||||||
|
adminPass = "admin"
|
||||||
|
}
|
||||||
|
|
||||||
data := &DbConfig{
|
data := &DbConfig{
|
||||||
DbConn: os.Getenv("DB_CONN"),
|
DbConn: os.Getenv("DB_CONN"),
|
||||||
DbHost: os.Getenv("DB_HOST"),
|
DbHost: os.Getenv("DB_HOST"),
|
||||||
|
@ -150,8 +161,8 @@ func EnvToConfig() *DbConfig {
|
||||||
Description: description,
|
Description: description,
|
||||||
Domain: os.Getenv("DOMAIN"),
|
Domain: os.Getenv("DOMAIN"),
|
||||||
Email: "",
|
Email: "",
|
||||||
Username: "admin",
|
Username: adminUser,
|
||||||
Password: "admin",
|
Password: adminPass,
|
||||||
Error: nil,
|
Error: nil,
|
||||||
Location: utils.Directory,
|
Location: utils.Directory,
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,11 +121,3 @@ func TestInsertNotifierDB(t *testing.T) {
|
||||||
err := InsertNotifierDB()
|
err := InsertNotifierDB()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExportStaticHTML(t *testing.T) {
|
|
||||||
t.SkipNow()
|
|
||||||
data := ExportIndexHTML()
|
|
||||||
assert.Contains(t, data, "https://github.com/hunterlong/statup️")
|
|
||||||
assert.Contains(t, data, "</body>")
|
|
||||||
assert.Contains(t, data, "</html>")
|
|
||||||
}
|
|
||||||
|
|
|
@ -297,7 +297,7 @@ func DatabaseMaintence() {
|
||||||
// DeleteAllSince will delete a specific table's records based on a time.
|
// DeleteAllSince will delete a specific table's records based on a time.
|
||||||
func DeleteAllSince(table string, date time.Time) {
|
func DeleteAllSince(table string, date time.Time) {
|
||||||
sql := fmt.Sprintf("DELETE FROM %v WHERE created_at < '%v';", table, date.Format("2006-01-02"))
|
sql := fmt.Sprintf("DELETE FROM %v WHERE created_at < '%v';", table, date.Format("2006-01-02"))
|
||||||
db := DbSession.Raw(sql)
|
db := DbSession.Exec(sql)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
utils.Log(2, db.Error)
|
utils.Log(2, db.Error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,73 +17,11 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"github.com/hunterlong/statup/source"
|
"github.com/hunterlong/statup/source"
|
||||||
"github.com/hunterlong/statup/types"
|
|
||||||
"github.com/hunterlong/statup/utils"
|
"github.com/hunterlong/statup/utils"
|
||||||
"html/template"
|
"html/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
func injectDatabase() {
|
|
||||||
Configs.Connect(false, utils.Directory)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExportIndexHTML returns the HTML of the index page as a string
|
|
||||||
func ExportIndexHTML() string {
|
|
||||||
source.Assets()
|
|
||||||
injectDatabase()
|
|
||||||
CoreApp.SelectAllServices(false)
|
|
||||||
CoreApp.UseCdn = types.NewNullBool(true)
|
|
||||||
for _, srv := range CoreApp.Services {
|
|
||||||
service := srv.(*Service)
|
|
||||||
service.Check(true)
|
|
||||||
fmt.Println(service.Name, service.Online, service.Latency)
|
|
||||||
}
|
|
||||||
nav, _ := source.TmplBox.String("nav.html")
|
|
||||||
footer, _ := source.TmplBox.String("footer.html")
|
|
||||||
render, err := source.TmplBox.String("index.html")
|
|
||||||
if err != nil {
|
|
||||||
utils.Log(3, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t := template.New("message")
|
|
||||||
t.Funcs(template.FuncMap{
|
|
||||||
"js": func(html string) template.JS {
|
|
||||||
return template.JS(html)
|
|
||||||
},
|
|
||||||
"safe": func(html string) template.HTML {
|
|
||||||
return template.HTML(html)
|
|
||||||
},
|
|
||||||
"VERSION": func() string {
|
|
||||||
return VERSION
|
|
||||||
},
|
|
||||||
"CoreApp": func() *Core {
|
|
||||||
return CoreApp
|
|
||||||
},
|
|
||||||
"USE_CDN": func() bool {
|
|
||||||
return CoreApp.UseCdn.Bool
|
|
||||||
},
|
|
||||||
"underscore": func(html string) string {
|
|
||||||
return utils.UnderScoreString(html)
|
|
||||||
},
|
|
||||||
"URL": func() string {
|
|
||||||
return "/"
|
|
||||||
},
|
|
||||||
"CHART_DATA": func() string {
|
|
||||||
return ExportChartsJs()
|
|
||||||
},
|
|
||||||
})
|
|
||||||
t, _ = t.Parse(nav)
|
|
||||||
t, _ = t.Parse(footer)
|
|
||||||
t.Parse(render)
|
|
||||||
var tpl bytes.Buffer
|
|
||||||
if err := t.Execute(&tpl, CoreApp); err != nil {
|
|
||||||
utils.Log(3, err)
|
|
||||||
}
|
|
||||||
result := tpl.String()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExportChartsJs renders the charts for the index page
|
// ExportChartsJs renders the charts for the index page
|
||||||
func ExportChartsJs() string {
|
func ExportChartsJs() string {
|
||||||
render, err := source.JsBox.String("charts.js")
|
render, err := source.JsBox.String("charts.js")
|
||||||
|
|
|
@ -36,21 +36,8 @@ type apiResponse struct {
|
||||||
Output interface{} `json:"output,omitempty"`
|
Output interface{} `json:"output,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func isAuthorized(r *http.Request) bool {
|
|
||||||
var token string
|
|
||||||
tokens, ok := r.Header["Authorization"]
|
|
||||||
if ok && len(tokens) >= 1 {
|
|
||||||
token = tokens[0]
|
|
||||||
token = strings.TrimPrefix(token, "Bearer ")
|
|
||||||
}
|
|
||||||
if token == core.CoreApp.ApiSecret {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func apiIndexHandler(w http.ResponseWriter, r *http.Request) {
|
func apiIndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -59,7 +46,7 @@ func apiIndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiRenewHandler(w http.ResponseWriter, r *http.Request) {
|
func apiRenewHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -142,7 +129,7 @@ func sendUnauthorizedJson(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(output)
|
json.NewEncoder(w).Encode(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isAPIAuthorized(r *http.Request) bool {
|
func isAuthorized(r *http.Request) bool {
|
||||||
utils.Http(r)
|
utils.Http(r)
|
||||||
if os.Getenv("GO_ENV") == "test" {
|
if os.Getenv("GO_ENV") == "test" {
|
||||||
return true
|
return true
|
||||||
|
@ -150,7 +137,13 @@ func isAPIAuthorized(r *http.Request) bool {
|
||||||
if IsAuthenticated(r) {
|
if IsAuthenticated(r) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if isAuthorized(r) {
|
var token string
|
||||||
|
tokens, ok := r.Header["Authorization"]
|
||||||
|
if ok && len(tokens) >= 1 {
|
||||||
|
token = tokens[0]
|
||||||
|
token = strings.TrimPrefix(token, "Bearer ")
|
||||||
|
}
|
||||||
|
if token == core.CoreApp.ApiSecret {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -27,7 +27,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func apiAllCheckinsHandler(w http.ResponseWriter, r *http.Request) {
|
func apiAllCheckinsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func apiAllCheckinsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiCheckinHandler(w http.ResponseWriter, r *http.Request) {
|
func apiCheckinHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,9 @@ import (
|
||||||
func dashboardHandler(w http.ResponseWriter, r *http.Request) {
|
func dashboardHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !IsAuthenticated(r) {
|
if !IsAuthenticated(r) {
|
||||||
err := core.ErrorResponse{}
|
err := core.ErrorResponse{}
|
||||||
executeResponse(w, r, "login.html", err, nil)
|
ExecuteResponse(w, r, "login.html", err, nil)
|
||||||
} else {
|
} else {
|
||||||
executeResponse(w, r, "dashboard.html", core.CoreApp, nil)
|
ExecuteResponse(w, r, "dashboard.html", core.CoreApp, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ func loginHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/dashboard", http.StatusSeeOther)
|
http.Redirect(w, r, "/dashboard", http.StatusSeeOther)
|
||||||
} else {
|
} else {
|
||||||
err := core.ErrorResponse{Error: "Incorrect login information submitted, try again."}
|
err := core.ErrorResponse{Error: "Incorrect login information submitted, try again."}
|
||||||
executeResponse(w, r, "login.html", err, nil)
|
ExecuteResponse(w, r, "login.html", err, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func helpHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
help := source.HelpMarkdown()
|
help := source.HelpMarkdown()
|
||||||
executeResponse(w, r, "help.html", help, nil)
|
ExecuteResponse(w, r, "help.html", help, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func logsHandler(w http.ResponseWriter, r *http.Request) {
|
func logsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -86,7 +86,7 @@ func logsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
logs = append(logs, utils.LastLines[i].FormatForHtml()+"\r\n")
|
logs = append(logs, utils.LastLines[i].FormatForHtml()+"\r\n")
|
||||||
}
|
}
|
||||||
utils.LockLines.Unlock()
|
utils.LockLines.Unlock()
|
||||||
executeResponse(w, r, "logs.html", logs, nil)
|
ExecuteResponse(w, r, "logs.html", logs, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func logsLineHandler(w http.ResponseWriter, r *http.Request) {
|
func logsLineHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -177,8 +177,8 @@ var handlerFuncs = func(w http.ResponseWriter, r *http.Request) template.FuncMap
|
||||||
|
|
||||||
var mainTmpl = `{{define "main" }} {{ template "base" . }} {{ end }}`
|
var mainTmpl = `{{define "main" }} {{ template "base" . }} {{ end }}`
|
||||||
|
|
||||||
// executeResponse will render a HTTP response for the front end user
|
// ExecuteResponse will render a HTTP response for the front end user
|
||||||
func executeResponse(w http.ResponseWriter, r *http.Request, file string, data interface{}, redirect interface{}) {
|
func ExecuteResponse(w http.ResponseWriter, r *http.Request, file string, data interface{}, redirect interface{}) {
|
||||||
utils.Http(r)
|
utils.Http(r)
|
||||||
if url, ok := redirect.(string); ok {
|
if url, ok := redirect.(string); ok {
|
||||||
http.Redirect(w, r, url, http.StatusSeeOther)
|
http.Redirect(w, r, url, http.StatusSeeOther)
|
||||||
|
@ -262,5 +262,5 @@ func executeJSResponse(w http.ResponseWriter, r *http.Request, file string, data
|
||||||
// error404Handler is a HTTP handler for 404 error pages
|
// error404Handler is a HTTP handler for 404 error pages
|
||||||
func error404Handler(w http.ResponseWriter, r *http.Request) {
|
func error404Handler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
executeResponse(w, r, "error_404.html", nil, nil)
|
ExecuteResponse(w, r, "error_404.html", nil, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/setup", http.StatusSeeOther)
|
http.Redirect(w, r, "/setup", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
executeResponse(w, r, "index.html", core.CoreApp, nil)
|
ExecuteResponse(w, r, "index.html", core.CoreApp, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -41,7 +41,7 @@ func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func trayHandler(w http.ResponseWriter, r *http.Request) {
|
func trayHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
executeResponse(w, r, "tray.html", core.CoreApp, nil)
|
ExecuteResponse(w, r, "tray.html", core.CoreApp, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DesktopInit will run the Statup server on a specific IP and port using SQLite database
|
// DesktopInit will run the Statup server on a specific IP and port using SQLite database
|
||||||
|
|
|
@ -31,7 +31,7 @@ func messagesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
messages, _ := core.SelectMessages()
|
messages, _ := core.SelectMessages()
|
||||||
executeResponse(w, r, "messages.html", messages, nil)
|
ExecuteResponse(w, r, "messages.html", messages, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func viewMessageHandler(w http.ResponseWriter, r *http.Request) {
|
func viewMessageHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -40,17 +40,17 @@ func viewMessageHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
id := utils.StringInt(vars["id"])
|
id := utils.ToInt(vars["id"])
|
||||||
message, err := core.SelectMessage(id)
|
message, err := core.SelectMessage(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
executeResponse(w, r, "message.html", message, nil)
|
ExecuteResponse(w, r, "message.html", message, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiAllMessagesHandler(w http.ResponseWriter, r *http.Request) {
|
func apiAllMessagesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ func apiAllMessagesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiMessageCreateHandler(w http.ResponseWriter, r *http.Request) {
|
func apiMessageCreateHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -85,12 +85,12 @@ func apiMessageCreateHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiMessageGetHandler(w http.ResponseWriter, r *http.Request) {
|
func apiMessageGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
message, err := core.SelectMessage(utils.StringInt(vars["id"]))
|
message, err := core.SelectMessage(utils.ToInt(vars["id"]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sendErrorJson(err, w, r)
|
sendErrorJson(err, w, r)
|
||||||
return
|
return
|
||||||
|
@ -100,12 +100,12 @@ func apiMessageGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiMessageDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
func apiMessageDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
message, err := core.SelectMessage(utils.StringInt(vars["id"]))
|
message, err := core.SelectMessage(utils.ToInt(vars["id"]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sendErrorJson(err, w, r)
|
sendErrorJson(err, w, r)
|
||||||
return
|
return
|
||||||
|
@ -119,12 +119,12 @@ func apiMessageDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiMessageUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
func apiMessageUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
message, err := core.SelectMessage(utils.StringInt(vars["id"]))
|
message, err := core.SelectMessage(utils.ToInt(vars["id"]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sendErrorJson(fmt.Errorf("message #%v was not found", vars["id"]), w, r)
|
sendErrorJson(fmt.Errorf("message #%v was not found", vars["id"]), w, r)
|
||||||
return
|
return
|
||||||
|
|
|
@ -27,7 +27,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) {
|
func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiNotifierGetHandler(w http.ResponseWriter, r *http.Request) {
|
func apiNotifierGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ func apiNotifierGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiNotifierUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
func apiNotifierUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -92,19 +92,19 @@ func testNotificationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
method := vars["method"]
|
method := vars["method"]
|
||||||
enabled := form.Get("enable")
|
enabled := form.Get("enable")
|
||||||
host := form.Get("host")
|
host := form.Get("host")
|
||||||
port := int(utils.StringInt(form.Get("port")))
|
port := int(utils.ToInt(form.Get("port")))
|
||||||
username := form.Get("username")
|
username := form.Get("username")
|
||||||
password := form.Get("password")
|
password := form.Get("password")
|
||||||
var1 := form.Get("var1")
|
var1 := form.Get("var1")
|
||||||
var2 := form.Get("var2")
|
var2 := form.Get("var2")
|
||||||
apiKey := form.Get("api_key")
|
apiKey := form.Get("api_key")
|
||||||
apiSecret := form.Get("api_secret")
|
apiSecret := form.Get("api_secret")
|
||||||
limits := int(utils.StringInt(form.Get("limits")))
|
limits := int(utils.ToInt(form.Get("limits")))
|
||||||
|
|
||||||
fakeNotifer, notif, err := notifier.SelectNotifier(method)
|
fakeNotifer, notif, err := notifier.SelectNotifier(method)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log(3, fmt.Sprintf("issue saving notifier %v: %v", method, err))
|
utils.Log(3, fmt.Sprintf("issue saving notifier %v: %v", method, err))
|
||||||
executeResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
ExecuteResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,7 @@ type PluginSelect struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func pluginSavedHandler(w http.ResponseWriter, r *http.Request) {
|
func pluginSavedHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
auth := IsAuthenticated(r)
|
if !isAuthorized(r) {
|
||||||
if !auth {
|
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ package handlers
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hunterlong/statup/core"
|
"github.com/hunterlong/statup/core"
|
||||||
"github.com/hunterlong/statup/utils"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -34,7 +33,6 @@ import (
|
||||||
//
|
//
|
||||||
|
|
||||||
func prometheusHandler(w http.ResponseWriter, r *http.Request) {
|
func prometheusHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
utils.Log(1, fmt.Sprintf("Prometheus /metrics Request From IP: %v\n", r.RemoteAddr))
|
|
||||||
if !isAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
|
|
|
@ -51,7 +51,7 @@ func servicesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
executeResponse(w, r, "services.html", core.CoreApp.Services, nil)
|
ExecuteResponse(w, r, "services.html", core.CoreApp.Services, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
type serviceOrder struct {
|
type serviceOrder struct {
|
||||||
|
@ -80,10 +80,10 @@ func servicesViewHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
fields := parseGet(r)
|
fields := parseGet(r)
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
|
|
||||||
startField := utils.StringInt(fields.Get("start"))
|
startField := utils.ToInt(fields.Get("start"))
|
||||||
endField := utils.StringInt(fields.Get("end"))
|
endField := utils.ToInt(fields.Get("end"))
|
||||||
group := r.Form.Get("group")
|
group := r.Form.Get("group")
|
||||||
serv := core.SelectService(utils.StringInt(vars["id"]))
|
serv := core.SelectService(utils.ToInt(vars["id"]))
|
||||||
if serv == nil {
|
if serv == nil {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
|
@ -113,16 +113,16 @@ func servicesViewHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
Data string
|
Data string
|
||||||
}{serv, start.Format(utils.FlatpickrReadable), end.Format(utils.FlatpickrReadable), start.Unix(), end.Unix(), data.ToString()}
|
}{serv, start.Format(utils.FlatpickrReadable), end.Format(utils.FlatpickrReadable), start.Unix(), end.Unix(), data.ToString()}
|
||||||
|
|
||||||
executeResponse(w, r, "service.html", out, nil)
|
ExecuteResponse(w, r, "service.html", out, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiServiceHandler(w http.ResponseWriter, r *http.Request) {
|
func apiServiceHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
servicer := core.SelectServicer(utils.StringInt(vars["id"]))
|
servicer := core.SelectServicer(utils.ToInt(vars["id"]))
|
||||||
if servicer == nil {
|
if servicer == nil {
|
||||||
sendErrorJson(errors.New("service not found"), w, r)
|
sendErrorJson(errors.New("service not found"), w, r)
|
||||||
return
|
return
|
||||||
|
@ -133,7 +133,7 @@ func apiServiceHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiCreateServiceHandler(w http.ResponseWriter, r *http.Request) {
|
func apiCreateServiceHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -154,12 +154,12 @@ func apiCreateServiceHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiServiceUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
func apiServiceUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
service := core.SelectServicer(utils.StringInt(vars["id"]))
|
service := core.SelectServicer(utils.ToInt(vars["id"]))
|
||||||
if service.Select() == nil {
|
if service.Select() == nil {
|
||||||
sendErrorJson(errors.New("service not found"), w, r)
|
sendErrorJson(errors.New("service not found"), w, r)
|
||||||
return
|
return
|
||||||
|
@ -178,7 +178,7 @@ func apiServiceUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func apiServiceDataHandler(w http.ResponseWriter, r *http.Request) {
|
func apiServiceDataHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
service := core.SelectService(utils.StringInt(vars["id"]))
|
service := core.SelectService(utils.ToInt(vars["id"]))
|
||||||
if service == nil {
|
if service == nil {
|
||||||
sendErrorJson(errors.New("service data not found"), w, r)
|
sendErrorJson(errors.New("service data not found"), w, r)
|
||||||
return
|
return
|
||||||
|
@ -188,8 +188,8 @@ func apiServiceDataHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if grouping == "" {
|
if grouping == "" {
|
||||||
grouping = "hour"
|
grouping = "hour"
|
||||||
}
|
}
|
||||||
startField := utils.StringInt(fields.Get("start"))
|
startField := utils.ToInt(fields.Get("start"))
|
||||||
endField := utils.StringInt(fields.Get("end"))
|
endField := utils.ToInt(fields.Get("end"))
|
||||||
|
|
||||||
if startField == 0 || endField == 0 {
|
if startField == 0 || endField == 0 {
|
||||||
startField = 0
|
startField = 0
|
||||||
|
@ -203,15 +203,15 @@ func apiServiceDataHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func apiServicePingDataHandler(w http.ResponseWriter, r *http.Request) {
|
func apiServicePingDataHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
service := core.SelectService(utils.StringInt(vars["id"]))
|
service := core.SelectService(utils.ToInt(vars["id"]))
|
||||||
if service == nil {
|
if service == nil {
|
||||||
sendErrorJson(errors.New("service not found"), w, r)
|
sendErrorJson(errors.New("service not found"), w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fields := parseGet(r)
|
fields := parseGet(r)
|
||||||
grouping := fields.Get("group")
|
grouping := fields.Get("group")
|
||||||
startField := utils.StringInt(fields.Get("start"))
|
startField := utils.ToInt(fields.Get("start"))
|
||||||
endField := utils.StringInt(fields.Get("end"))
|
endField := utils.ToInt(fields.Get("end"))
|
||||||
obj := core.GraphDataRaw(service, time.Unix(startField, 0), time.Unix(endField, 0), grouping, "ping_time")
|
obj := core.GraphDataRaw(service, time.Unix(startField, 0), time.Unix(endField, 0), grouping, "ping_time")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
@ -219,12 +219,12 @@ func apiServicePingDataHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiServiceDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
func apiServiceDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
service := core.SelectService(utils.StringInt(vars["id"]))
|
service := core.SelectService(utils.ToInt(vars["id"]))
|
||||||
if service == nil {
|
if service == nil {
|
||||||
sendErrorJson(errors.New("service not found"), w, r)
|
sendErrorJson(errors.New("service not found"), w, r)
|
||||||
return
|
return
|
||||||
|
@ -238,7 +238,7 @@ func apiServiceDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiAllServicesHandler(w http.ResponseWriter, r *http.Request) {
|
func apiAllServicesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ func servicesDeleteFailuresHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
service := core.SelectService(utils.StringInt(vars["id"]))
|
service := core.SelectService(utils.ToInt(vars["id"]))
|
||||||
service.DeleteFailures()
|
service.DeleteFailures()
|
||||||
executeResponse(w, r, "services.html", core.CoreApp.Services, "/services")
|
ExecuteResponse(w, r, "services.html", core.CoreApp.Services, "/services")
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ func settingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
executeResponse(w, r, "settings.html", core.CoreApp, nil)
|
ExecuteResponse(w, r, "settings.html", core.CoreApp, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveSettingsHandler(w http.ResponseWriter, r *http.Request) {
|
func saveSettingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -68,7 +68,7 @@ func saveSettingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
app.UseCdn = types.NewNullBool(r.PostForm.Get("enable_cdn") == "on")
|
app.UseCdn = types.NewNullBool(r.PostForm.Get("enable_cdn") == "on")
|
||||||
core.CoreApp, _ = core.UpdateCore(app)
|
core.CoreApp, _ = core.UpdateCore(app)
|
||||||
//notifiers.OnSettingsSaved(core.CoreApp.ToCore())
|
//notifiers.OnSettingsSaved(core.CoreApp.ToCore())
|
||||||
executeResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
ExecuteResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveSASSHandler(w http.ResponseWriter, r *http.Request) {
|
func saveSASSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -85,7 +85,7 @@ func saveSASSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
source.SaveAsset([]byte(mobile), utils.Directory, "scss/mobile.scss")
|
source.SaveAsset([]byte(mobile), utils.Directory, "scss/mobile.scss")
|
||||||
source.CompileSASS(utils.Directory)
|
source.CompileSASS(utils.Directory)
|
||||||
resetRouter()
|
resetRouter()
|
||||||
executeResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
ExecuteResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveAssetsHandler(w http.ResponseWriter, r *http.Request) {
|
func saveAssetsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -105,7 +105,7 @@ func saveAssetsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
utils.Log(3, "Default 'base.css' was inserted because SASS did not work.")
|
utils.Log(3, "Default 'base.css' was inserted because SASS did not work.")
|
||||||
}
|
}
|
||||||
resetRouter()
|
resetRouter()
|
||||||
executeResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
ExecuteResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteAssetsHandler(w http.ResponseWriter, r *http.Request) {
|
func deleteAssetsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -115,12 +115,12 @@ func deleteAssetsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
source.DeleteAllAssets(utils.Directory)
|
source.DeleteAllAssets(utils.Directory)
|
||||||
resetRouter()
|
resetRouter()
|
||||||
executeResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
ExecuteResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseId(r *http.Request) int64 {
|
func parseId(r *http.Request) int64 {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
return utils.StringInt(vars["id"])
|
return utils.ToInt(vars["id"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseForm(r *http.Request) url.Values {
|
func parseForm(r *http.Request) url.Values {
|
||||||
|
|
|
@ -34,7 +34,7 @@ func setupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data, _ = core.LoadUsingEnv()
|
data, _ = core.LoadUsingEnv()
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
executeResponse(w, r, "setup.html", data, nil)
|
ExecuteResponse(w, r, "setup.html", data, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func processSetupHandler(w http.ResponseWriter, r *http.Request) {
|
func processSetupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -49,7 +49,7 @@ func processSetupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
dbPass := r.PostForm.Get("db_password")
|
dbPass := r.PostForm.Get("db_password")
|
||||||
dbDatabase := r.PostForm.Get("db_database")
|
dbDatabase := r.PostForm.Get("db_database")
|
||||||
dbConn := r.PostForm.Get("db_connection")
|
dbConn := r.PostForm.Get("db_connection")
|
||||||
dbPort := utils.StringInt(r.PostForm.Get("db_port"))
|
dbPort := utils.ToInt(r.PostForm.Get("db_port"))
|
||||||
project := r.PostForm.Get("project")
|
project := r.PostForm.Get("project")
|
||||||
username := r.PostForm.Get("username")
|
username := r.PostForm.Get("username")
|
||||||
password := r.PostForm.Get("password")
|
password := r.PostForm.Get("password")
|
||||||
|
@ -126,5 +126,5 @@ func processSetupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupResponseError(w http.ResponseWriter, r *http.Request, a interface{}) {
|
func setupResponseError(w http.ResponseWriter, r *http.Request, a interface{}) {
|
||||||
executeResponse(w, r, "setup.html", a, nil)
|
ExecuteResponse(w, r, "setup.html", a, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ func usersHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
users, _ := core.SelectAllUsers()
|
users, _ := core.SelectAllUsers()
|
||||||
executeResponse(w, r, "users.html", users, nil)
|
ExecuteResponse(w, r, "users.html", users, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func usersEditHandler(w http.ResponseWriter, r *http.Request) {
|
func usersEditHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -44,16 +44,16 @@ func usersEditHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
id, _ := strconv.Atoi(vars["id"])
|
id, _ := strconv.Atoi(vars["id"])
|
||||||
user, _ := core.SelectUser(int64(id))
|
user, _ := core.SelectUser(int64(id))
|
||||||
executeResponse(w, r, "user.html", user, nil)
|
ExecuteResponse(w, r, "user.html", user, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiUserHandler(w http.ResponseWriter, r *http.Request) {
|
func apiUserHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
user, err := core.SelectUser(utils.StringInt(vars["id"]))
|
user, err := core.SelectUser(utils.ToInt(vars["id"]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sendErrorJson(err, w, r)
|
sendErrorJson(err, w, r)
|
||||||
return
|
return
|
||||||
|
@ -64,12 +64,12 @@ func apiUserHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiUserUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
func apiUserUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
user, err := core.SelectUser(utils.StringInt(vars["id"]))
|
user, err := core.SelectUser(utils.ToInt(vars["id"]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sendErrorJson(fmt.Errorf("user #%v was not found", vars["id"]), w, r)
|
sendErrorJson(fmt.Errorf("user #%v was not found", vars["id"]), w, r)
|
||||||
return
|
return
|
||||||
|
@ -85,7 +85,7 @@ func apiUserUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiUserDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
func apiUserDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ func apiUserDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
sendErrorJson(errors.New("cannot delete the last user"), w, r)
|
sendErrorJson(errors.New("cannot delete the last user"), w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user, err := core.SelectUser(utils.StringInt(vars["id"]))
|
user, err := core.SelectUser(utils.ToInt(vars["id"]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sendErrorJson(err, w, r)
|
sendErrorJson(err, w, r)
|
||||||
return
|
return
|
||||||
|
@ -109,7 +109,7 @@ func apiUserDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiAllUsersHandler(w http.ResponseWriter, r *http.Request) {
|
func apiAllUsersHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ func apiAllUsersHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiCreateUsersHandler(w http.ResponseWriter, r *http.Request) {
|
func apiCreateUsersHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isAPIAuthorized(r) {
|
if !isAuthorized(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,15 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringInt converts a string to an int64
|
// ToInt converts a int to a string
|
||||||
func StringInt(s string) int64 {
|
func ToInt(s interface{}) int64 {
|
||||||
num, _ := strconv.Atoi(s)
|
switch v := s.(type) {
|
||||||
return int64(num)
|
case string:
|
||||||
|
val, _ := strconv.Atoi(v)
|
||||||
|
return int64(val)
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToString converts a int to a string
|
// ToString converts a int to a string
|
||||||
|
@ -55,14 +60,11 @@ func ToString(s interface{}) string {
|
||||||
case int, int32, int64:
|
case int, int32, int64:
|
||||||
return fmt.Sprintf("%v", v)
|
return fmt.Sprintf("%v", v)
|
||||||
case float32, float64:
|
case float32, float64:
|
||||||
return fmt.Sprintf("%v", v)
|
return fmt.Sprintf("%f", v)
|
||||||
case []byte:
|
case []byte:
|
||||||
return string(v)
|
return string(v)
|
||||||
case bool:
|
case bool:
|
||||||
if v {
|
return fmt.Sprintf("%t", v)
|
||||||
return "true"
|
|
||||||
}
|
|
||||||
return "false"
|
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf("%v", v)
|
return fmt.Sprintf("%v", v)
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,19 +106,15 @@ func ExampleToString() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringInt(t *testing.T) {
|
func TestStringInt(t *testing.T) {
|
||||||
assert.Equal(t, int64(1), StringInt("1"))
|
assert.Equal(t, int64(1), ToString("1"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleStringInt() {
|
func ExampleStringInt() {
|
||||||
amount := "42"
|
amount := "42"
|
||||||
fmt.Print(StringInt(amount))
|
fmt.Print(ToString(amount))
|
||||||
// Output: 42
|
// Output: 42
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDbTime(t *testing.T) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTimezone(t *testing.T) {
|
func TestTimezone(t *testing.T) {
|
||||||
zone := float32(-4.0)
|
zone := float32(-4.0)
|
||||||
loc, _ := time.LoadLocation("America/Los_Angeles")
|
loc, _ := time.LoadLocation("America/Los_Angeles")
|
||||||
|
|
Loading…
Reference in New Issue