pull/10/head
Hunter Long 2018-06-09 18:47:57 -07:00
parent decd9a2fc5
commit ad78d2250a
4 changed files with 28 additions and 43 deletions

View File

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

23
main.go
View File

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

View File

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

19
web.go
View File

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