upgrades - plugins

pull/10/head
Hunter Long 2018-06-13 23:50:47 -07:00
parent 808a2b60f1
commit e37f647093
7 changed files with 29 additions and 17 deletions

View File

@ -16,6 +16,7 @@ type Core struct {
PluginFields []PluginSelect PluginFields []PluginSelect
} }
func SelectCore() (*Core, error) { func SelectCore() (*Core, error) {
var core Core var core Core
rows, err := db.Query("SELECT * FROM core") rows, err := db.Query("SELECT * FROM core")

View File

@ -9,14 +9,15 @@ import (
"time" "time"
) )
func DbConnection() { func DbConnection() error {
var err 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) 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) db, err = sql.Open("postgres", dbinfo)
if err != nil { if err != nil {
panic(err) return err
} }
plugin.SetDatabase(db) plugin.SetDatabase(db)
return err
} }
func UpgradeDatabase() { func UpgradeDatabase() {

View File

@ -16,7 +16,7 @@
<div class="container"> <div class="container">
<div class="row"> <div class="col-12">
{{ range .Services }} {{ range .Services }}
<div class="col-12 mb-4"> <div class="col-12 mb-4">

18
main.go
View File

@ -232,11 +232,12 @@ func UpdateSettings(p plugin.Info, data map[string]string) {
//} //}
func main() { func main() {
var err error
VERSION = "1.1.1" VERSION = "1.1.1"
fmt.Printf("Starting Statup v%v\n", VERSION) fmt.Printf("Starting Statup v%v\n", VERSION)
RenderBoxes() RenderBoxes()
configs = LoadConfig() configs, err = LoadConfig()
if configs == nil { if err != nil {
fmt.Println("config.yml file not found - starting in setup mode") fmt.Println("config.yml file not found - starting in setup mode")
setupMode = true setupMode = true
RunHTTPServer() RunHTTPServer()
@ -246,7 +247,10 @@ func main() {
func mainProcess() { func mainProcess() {
var err error var err error
DbConnection() err = DbConnection()
if err != nil {
throw(err)
}
core, err = SelectCore() core, err = SelectCore()
if err != nil { if err != nil {
throw(err) throw(err)
@ -323,14 +327,14 @@ func RenderBoxes() {
tmplBox = rice.MustFindBox("html/tmpl") tmplBox = rice.MustFindBox("html/tmpl")
} }
func LoadConfig() *Config { func LoadConfig() (*Config, error) {
var config Config var config Config
file, err := ioutil.ReadFile("config.yml") file, err := ioutil.ReadFile("config.yml")
if err != nil { if err != nil {
return nil return nil, err
} }
yaml.Unmarshal(file, &config) err = yaml.Unmarshal(file, &config)
return &config return &config, err
} }
func HashPassword(password string) string { func HashPassword(password string) string {

View File

@ -31,12 +31,14 @@ func TestMakeConfig(t *testing.T) {
} }
func TestSetConfig(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) { func TestRun(t *testing.T) {
configs = LoadConfig() mainProcess()
go mainProcess()
time.Sleep(15 * time.Second) time.Sleep(15 * time.Second)
} }

View File

@ -69,9 +69,14 @@ func (c *DbConfig) Save() error {
config.WriteString(string(data)) config.WriteString(string(data))
config.Close() config.Close()
configs = LoadConfig() configs, err = LoadConfig()
if err != nil {
DbConnection() return err
}
err = DbConnection()
if err != nil {
return err
}
DropDatabase() DropDatabase()
CreateDatabase() 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() 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()

View File

@ -4,7 +4,6 @@ CREATE TABLE core (
api_key text, api_key text,
api_secret text, api_secret text,
version text, version text,
plugins_enabled text,
); );
CREATE TABLE users ( CREATE TABLE users (