summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus32015-02-19 13:30:54 +0100
committerHorus32015-02-19 13:30:54 +0100
commit02e6a8b9ae3596ee1c405cdd1541c5cc59b50e3a (patch)
tree157a800cc381e78bb03b8868417db8fe12ca8239
parentd9749f16e15739c7652b05af391af9e59e2307d6 (diff)
downloadstatuspage-02e6a8b9ae3596ee1c405cdd1541c5cc59b50e3a.tar.gz
Static file handling and autoimport the db-driver from Makefile.
-rw-r--r--app/Makefile5
-rw-r--r--app/db.go21
-rw-r--r--app/fetch.go14
-rw-r--r--app/handler.go5
-rw-r--r--app/main.go6
-rw-r--r--static/css/style.css72
-rw-r--r--static/img/favicon.icobin0 -> 5242 bytes
-rw-r--r--views/admin.html (renamed from templates/admin.html)0
-rw-r--r--views/footer.html (renamed from templates/footer.html)7
-rw-r--r--views/header.html (renamed from templates/header.html)0
-rw-r--r--views/index.html (renamed from templates/index.html)0
-rw-r--r--views/jobs.html (renamed from templates/jobs.html)0
-rw-r--r--views/login.html (renamed from templates/login.html)0
-rw-r--r--views/navbar.html (renamed from templates/navbar.html)0
-rw-r--r--views/register.html (renamed from templates/register.html)0
15 files changed, 106 insertions, 24 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:
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
--- /dev/null
+++ b/static/img/favicon.ico
Binary files differ
diff --git a/templates/admin.html b/views/admin.html
index e69de29..e69de29 100644
--- a/templates/admin.html
+++ b/views/admin.html
diff --git a/templates/footer.html b/views/footer.html
index b62b56f..408581d 100644
--- a/templates/footer.html
+++ b/views/footer.html
@@ -1,5 +1,5 @@
{{range .moreScripts}}
- <script src="/public/{{.}}" type="text/javascript" charset="utf-8"></script>
+ <script src="/static/js/{{.}}" type="text/javascript" charset="utf-8"></script>
{{end}}
<div class="footer">
<div class="container">
@@ -10,7 +10,8 @@
</div>
</div>
</div>
-<script src="//code.jquery.com/jquery-1.10.1.min.js"></script>
-<script src="/static/js/bootstrap.js"></script>
+<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script
+<!--script src="/static/js/bootstrap.js"></script-->
</body>
</html>
diff --git a/templates/header.html b/views/header.html
index 2875487..2875487 100644
--- a/templates/header.html
+++ b/views/header.html
diff --git a/templates/index.html b/views/index.html
index e69de29..e69de29 100644
--- a/templates/index.html
+++ b/views/index.html
diff --git a/templates/jobs.html b/views/jobs.html
index c0d68ac..c0d68ac 100644
--- a/templates/jobs.html
+++ b/views/jobs.html
diff --git a/templates/login.html b/views/login.html
index e69de29..e69de29 100644
--- a/templates/login.html
+++ b/views/login.html
diff --git a/templates/navbar.html b/views/navbar.html
index 6cb06b6..6cb06b6 100644
--- a/templates/navbar.html
+++ b/views/navbar.html
diff --git a/templates/register.html b/views/register.html
index e69de29..e69de29 100644
--- a/templates/register.html
+++ b/views/register.html