From e37f647093e460676b24c27a720de9e07fa79d75 Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Wed, 13 Jun 2018 23:50:47 -0700 Subject: [PATCH] upgrades - plugins --- core.go | 1 + database.go | 5 +++-- html/tmpl/index.html | 2 +- main.go | 18 +++++++++++------- main_test.go | 8 +++++--- setup.go | 11 ++++++++--- sql/up.sql | 1 - 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/core.go b/core.go index 4e5a3cfb..82e0a5e2 100644 --- a/core.go +++ b/core.go @@ -16,6 +16,7 @@ type Core struct { PluginFields []PluginSelect } + func SelectCore() (*Core, error) { var core Core rows, err := db.Query("SELECT * FROM core") diff --git a/database.go b/database.go index 71aa1788..d5f28ae9 100644 --- a/database.go +++ b/database.go @@ -9,14 +9,15 @@ import ( "time" ) -func DbConnection() { +func DbConnection() error { var err error dbinfo := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", configs.Host, configs.Port, configs.User, configs.Password, configs.Database) db, err = sql.Open("postgres", dbinfo) if err != nil { - panic(err) + return err } plugin.SetDatabase(db) + return err } func UpgradeDatabase() { diff --git a/html/tmpl/index.html b/html/tmpl/index.html index 9201bea1..12d052ff 100644 --- a/html/tmpl/index.html +++ b/html/tmpl/index.html @@ -16,7 +16,7 @@
-
+
{{ range .Services }}
diff --git a/main.go b/main.go index a385142b..427e723c 100644 --- a/main.go +++ b/main.go @@ -232,11 +232,12 @@ func UpdateSettings(p plugin.Info, data map[string]string) { //} func main() { + var err error VERSION = "1.1.1" fmt.Printf("Starting Statup v%v\n", VERSION) RenderBoxes() - configs = LoadConfig() - if configs == nil { + configs, err = LoadConfig() + if err != nil { fmt.Println("config.yml file not found - starting in setup mode") setupMode = true RunHTTPServer() @@ -246,7 +247,10 @@ func main() { func mainProcess() { var err error - DbConnection() + err = DbConnection() + if err != nil { + throw(err) + } core, err = SelectCore() if err != nil { throw(err) @@ -323,14 +327,14 @@ func RenderBoxes() { tmplBox = rice.MustFindBox("html/tmpl") } -func LoadConfig() *Config { +func LoadConfig() (*Config, error) { var config Config file, err := ioutil.ReadFile("config.yml") if err != nil { - return nil + return nil, err } - yaml.Unmarshal(file, &config) - return &config + err = yaml.Unmarshal(file, &config) + return &config, err } func HashPassword(password string) string { diff --git a/main_test.go b/main_test.go index 012418be..6943651e 100644 --- a/main_test.go +++ b/main_test.go @@ -31,12 +31,14 @@ func TestMakeConfig(t *testing.T) { } func TestSetConfig(t *testing.T) { - configs = LoadConfig() + var err error + configs, err = LoadConfig() + assert.Nil(t, err) + time.Sleep(2 * time.Second) } func TestRun(t *testing.T) { - configs = LoadConfig() - go mainProcess() + mainProcess() time.Sleep(15 * time.Second) } diff --git a/setup.go b/setup.go index cae2ca1a..1e124899 100644 --- a/setup.go +++ b/setup.go @@ -69,9 +69,14 @@ func (c *DbConfig) Save() error { config.WriteString(string(data)) config.Close() - configs = LoadConfig() - - DbConnection() + configs, err = LoadConfig() + if err != nil { + return err + } + err = DbConnection() + if err != nil { + return err + } DropDatabase() CreateDatabase() db.QueryRow("INSERT INTO core (name, config, api_key, api_secret, version) VALUES($1,$2,$3,$4,$5);", c.Project, "config.yml", NewSHA1Hash(5), NewSHA1Hash(10), VERSION).Scan() diff --git a/sql/up.sql b/sql/up.sql index f16c0d34..3e3c01ff 100644 --- a/sql/up.sql +++ b/sql/up.sql @@ -4,7 +4,6 @@ CREATE TABLE core ( api_key text, api_secret text, version text, - plugins_enabled text, ); CREATE TABLE users (