diff --git a/core.go b/core.go index c67c8cfb..09f92f02 100644 --- a/core.go +++ b/core.go @@ -1,15 +1,13 @@ package main - type Core struct { - Name string + Name string Config string - Key string + Key string Secret string Version string } - func SelectCore() (*Core, error) { var core Core rows, err := db.Query("SELECT * FROM core") diff --git a/main.go b/main.go index 7e6f4518..6777d016 100644 --- a/main.go +++ b/main.go @@ -2,25 +2,25 @@ package main import ( "database/sql" + "fmt" "github.com/GeertJohan/go.rice" "github.com/go-yaml/yaml" "github.com/gorilla/sessions" _ "github.com/lib/pq" "golang.org/x/crypto/bcrypt" "io/ioutil" - "fmt" ) var ( - db *sql.DB - configs *Config - core *Core - store *sessions.CookieStore - VERSION string - sqlBox *rice.Box - cssBox *rice.Box - jsBox *rice.Box - tmplBox *rice.Box + db *sql.DB + configs *Config + core *Core + store *sessions.CookieStore + VERSION string + sqlBox *rice.Box + cssBox *rice.Box + jsBox *rice.Box + tmplBox *rice.Box setupMode bool ) @@ -46,7 +46,6 @@ func main() { mainProcess() } - func mainProcess() { var err error DbConnection() @@ -60,8 +59,6 @@ func mainProcess() { } } - - func RenderBoxes() { sqlBox = rice.MustFindBox("sql") cssBox = rice.MustFindBox("html/css") diff --git a/setup.go b/setup.go index a85a50d7..cae2ca1a 100644 --- a/setup.go +++ b/setup.go @@ -1,23 +1,23 @@ package main import ( - "net/http" - "strconv" - "os" "github.com/go-yaml/yaml" + "net/http" + "os" + "strconv" "time" ) type DbConfig struct { - DbConn string `yaml:"connection"` - DbHost string `yaml:"host"` - DbUser string `yaml:"user"` - DbPass string `yaml:"password"` - DbData string `yaml:"database"` - DbPort int `yaml:"port"` + DbConn string `yaml:"connection"` + DbHost string `yaml:"host"` + DbUser string `yaml:"user"` + DbPass string `yaml:"password"` + DbData string `yaml:"database"` + DbPort int `yaml:"port"` Project string `yaml:"-"` - Username string `yaml:"-"` - Password string `yaml:"-"` + Username string `yaml:"-"` + Password string `yaml:"-"` } func ProcessSetupHandler(w http.ResponseWriter, r *http.Request) { @@ -56,7 +56,6 @@ func ProcessSetupHandler(w http.ResponseWriter, r *http.Request) { } - func (c *DbConfig) Save() error { var err error config, err := os.Create("config.yml") diff --git a/web.go b/web.go index 13563c97..a7f351fe 100644 --- a/web.go +++ b/web.go @@ -91,7 +91,6 @@ func CreateServiceHandler(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/services", http.StatusSeeOther) } - func SetupHandler(w http.ResponseWriter, r *http.Request) { setupFile, err := tmplBox.String("setup.html") if err != nil { @@ -109,31 +108,23 @@ type index struct { } func IndexHandler(w http.ResponseWriter, r *http.Request) { - //session, _ := store.Get(r, "apizer_auth") - //if auth, ok := session.Values["authenticated"].(bool); !ok || !auth { - // http.Redirect(w, r, "/", http.StatusSeeOther) - // return - //} - - if setupMode { + if core == nil { http.Redirect(w, r, "/setup", http.StatusSeeOther) return } - dashboardFile, err := tmplBox.String("index.html") + indexFile, err := tmplBox.String("index.html") if err != nil { panic(err) } - dashboardTmpl, err := template.New("message").Funcs(template.FuncMap{ + indexTmpl, err := template.New("message").Funcs(template.FuncMap{ "js": func(html string) template.JS { return template.JS(html) }, - }).Parse(dashboardFile) - + }).Parse(indexFile) out := index{SelectAllServices()} - - dashboardTmpl.Execute(w, out) + indexTmpl.Execute(w, out) } func DashboardHandler(w http.ResponseWriter, r *http.Request) {