diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/Makefile | 5 | ||||
| -rw-r--r-- | app/db.go | 21 | ||||
| -rw-r--r-- | app/fetch.go | 14 | ||||
| -rw-r--r-- | app/handler.go | 5 | ||||
| -rw-r--r-- | app/main.go | 6 |
5 files changed, 30 insertions, 21 deletions
diff --git a/app/Makefile b/app/Makefile index f246e69..120635a 100644 --- a/app/Makefile +++ b/app/Makefile @@ -1,9 +1,12 @@ export STATUS_DB_DRIVER:=sqlite3 export STATUS_DB_CREDENTIALS:=../db/status.db +export STATUS_DB_IMPORT_DRIVER:=github.com/mattn/go-sqlite3 all: kill build run clean: + @echo "Removing import file..." + @rm import.go || true @echo "Removing sqlite3 database..." @rm $$STATUS_DB_CREDENTIALS @echo "Removing binary..." @@ -11,6 +14,8 @@ clean: @echo "Done" build: + @echo "package main" > import.go + @echo "import (_ \"$$STATUS_DB_IMPORT_DRIVER\")" >> import.go go build -o statuspage run: @@ -2,22 +2,13 @@ package main import ( "github.com/jinzhu/gorm" - _ "github.com/mattn/go-sqlite3" "log" "os" ) -//var Db gorm.DB -var dbdriver = os.Getenv("STATUS_DB_DRIVER") -var dbcred = os.Getenv("STATUS_DB_CREDENTIALS") -var Db, dberr = gorm.Open(dbdriver, dbcred) +var Db, dberr = gorm.Open(os.Getenv("STATUS_DB_DRIVER"), os.Getenv("STATUS_DB_CREDENTIALS")) func InitDB() { - /* - dbdriver := os.Getenv("STATUS_DB_DRIVER") - dbcred := os.Getenv("STATUS_DB_CREDENTIALS") - Db, err := gorm.Open(dbdriver, dbcred) - */ if dberr != nil { log.Panic(dberr) } @@ -26,15 +17,13 @@ func InitDB() { log.Panic(err) } - // u := User{} + u := User{} h := Host{} - // Db.Debug().AutoMigrate(&u) + Db.Debug().AutoMigrate(&u) db := Db log.Println(db) db.Debug().AutoMigrate(&h) - /* - Db.Model(&u).AddUniqueIndex("idx_user_name", "name") - Db.Model(&u).AddUniqueIndex("idx_user_email", "email") - */ + Db.Model(&u).AddUniqueIndex("idx_user_name", "name") + Db.Model(&u).AddUniqueIndex("idx_user_email", "email") } diff --git a/app/fetch.go b/app/fetch.go index 27aa628..cd8206b 100644 --- a/app/fetch.go +++ b/app/fetch.go @@ -1,9 +1,17 @@ package main -/* import ( "fmt" + "github.com/robfig/cron" + "time" ) -func -*/ +func run() { + c := cron.New() + c.AddFunc("@every 1m", printStatus) + c.Start() +} + +func printStatus() { + fmt.Println(time.Now()) +} diff --git a/app/handler.go b/app/handler.go index f87e92a..d76782f 100644 --- a/app/handler.go +++ b/app/handler.go @@ -12,6 +12,11 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { // w.Write() } +/* +func StaticHandler(w http.ResponseWrite, r *http.Request) { +} +*/ + func RegisterHandler(w http.ResponseWriter, r *http.Request) { log.Println("Processing registration!") fmt.Fprintf(w, "Processing registration! \n") diff --git a/app/main.go b/app/main.go index 0a8b7dd..ac2f27b 100644 --- a/app/main.go +++ b/app/main.go @@ -9,14 +9,16 @@ import ( var decoder = schema.NewDecoder() -//var mainTempl = template.Must(template.New("global").ParseFiles("templates/header.html", "templates/navbar.html", "templates/footer.html")) -var mainTempl = template.Must(template.New("global").ParseGlob("../templates/*.html")) +var mainTempl = template.Must(template.New("global").ParseGlob("../views/*.html")) func main() { + run() InitDB() r := mux.NewRouter() r.HandleFunc("/", IndexHandler) + //r.HandleFunc("/static", StaticHandler) + r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./../static")))) r.HandleFunc("/register", RegisterHandler).Methods("POST") r.HandleFunc("/register", PrintRegisterHandler).Methods("GET") r.HandleFunc("/new", AddNewJobHandler).Methods("POST") |
