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
}
func SelectCore() (*Core, error) {
var core Core
rows, err := db.Query("SELECT * FROM core")

View File

@ -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() {

View File

@ -16,7 +16,7 @@
<div class="container">
<div class="row">
<div class="col-12">
{{ range .Services }}
<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() {
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 {

View File

@ -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)
}

View File

@ -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()

View File

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