From 02e6a8b9ae3596ee1c405cdd1541c5cc59b50e3a Mon Sep 17 00:00:00 2001 From: Horus3 Date: Thu, 19 Feb 2015 13:30:54 +0100 Subject: Static file handling and autoimport the db-driver from Makefile. --- app/Makefile | 5 ++++ app/db.go | 21 ++++---------- app/fetch.go | 14 ++++++++-- app/handler.go | 5 ++++ app/main.go | 6 ++-- static/css/style.css | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ static/img/favicon.ico | Bin 0 -> 5242 bytes templates/admin.html | 0 templates/footer.html | 16 ----------- templates/header.html | 19 ------------- templates/index.html | 0 templates/jobs.html | 9 ------ templates/login.html | 0 templates/navbar.html | 23 ---------------- templates/register.html | 0 views/admin.html | 0 views/footer.html | 17 ++++++++++++ views/header.html | 19 +++++++++++++ views/index.html | 0 views/jobs.html | 9 ++++++ views/login.html | 0 views/navbar.html | 23 ++++++++++++++++ views/register.html | 0 23 files changed, 170 insertions(+), 88 deletions(-) create mode 100644 static/css/style.css create mode 100644 static/img/favicon.ico delete mode 100644 templates/admin.html delete mode 100644 templates/footer.html delete mode 100644 templates/header.html delete mode 100644 templates/index.html delete mode 100644 templates/jobs.html delete mode 100644 templates/login.html delete mode 100644 templates/navbar.html delete mode 100644 templates/register.html create mode 100644 views/admin.html create mode 100644 views/footer.html create mode 100644 views/header.html create mode 100644 views/index.html create mode 100644 views/jobs.html create mode 100644 views/login.html create mode 100644 views/navbar.html create mode 100644 views/register.html 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: diff --git a/app/db.go b/app/db.go index dc9a15d..19a59f0 100644 --- a/app/db.go +++ b/app/db.go @@ -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") diff --git a/static/css/style.css b/static/css/style.css new file mode 100644 index 0000000..2da531b --- /dev/null +++ b/static/css/style.css @@ -0,0 +1,72 @@ +html { + position: relative; + min-height: 100%; +} + +body { + margin-bottom: 60px; +} + +a { + color: #3083D6; +} + +/* navbar */ + +.navbar-default { + background-color: #3083D6 ; + border-color: #3083D6 ; + background: #3083D6 ; +} + +.navbar-default .navbar-brand { + color: white; +} + +.navbar-default .navbar-brand:hover, +.navbar-default .navbar-brand:focus { +} + +.navbar-default .navbar-nav > li > a { + color: white; +} + +.noscript { + background-color: #dd5148; + color: white; +} + +/* footer */ + +.footer { + background-color: #3083D6 ; + border-color: #3083D6 ; + background: #3083D6 ; + color: white ; + position: absolute; + bottom: 0; + width: 100%; +} + +.footer-a { + color: white; +} + +.footer-a:hover { + color: white; + text-decoration: underline; +} + +.underline { + text-decoration: underline; +} + +.actives { + color: white !important; +/* text-decoration: underline; */ + font-weight: bold; +} + +.grey { + color: #737373; +} diff --git a/static/img/favicon.ico b/static/img/favicon.ico new file mode 100644 index 0000000..41f6475 Binary files /dev/null and b/static/img/favicon.ico differ diff --git a/templates/admin.html b/templates/admin.html deleted file mode 100644 index e69de29..0000000 diff --git a/templates/footer.html b/templates/footer.html deleted file mode 100644 index b62b56f..0000000 --- a/templates/footer.html +++ /dev/null @@ -1,16 +0,0 @@ - {{range .moreScripts}} - - {{end}} -
- - -