summaryrefslogtreecommitdiff
path: root/app/handler.go
diff options
context:
space:
mode:
authorHorus32015-02-21 14:50:00 +0100
committerHorus32015-02-21 14:50:00 +0100
commitb58e21a525e7e4aeda3ec51bfcb07390af8be465 (patch)
tree9974d885ae2c81052e881e00207677e80d9f6fc7 /app/handler.go
parentc92989a8fc738094b205094a1bdd458a40c23d9c (diff)
downloadstatuspage-b58e21a525e7e4aeda3ec51bfcb07390af8be465.tar.gz
Index page is now cached.
Diffstat (limited to 'app/handler.go')
-rw-r--r--app/handler.go32
1 files changed, 26 insertions, 6 deletions
diff --git a/app/handler.go b/app/handler.go
index ad66657..9a3352f 100644
--- a/app/handler.go
+++ b/app/handler.go
@@ -3,19 +3,39 @@ package main
import (
"fmt"
// "html/template"
+ "encoding/json"
+ "github.com/garyburd/redigo/redis"
"log"
"net/http"
)
func IndexHandler(w http.ResponseWriter, r *http.Request) {
- fmt.Fprintf(w, "Hello World! \n")
- // w.Write()
-}
+ log.Println("Print IndexHandler")
+
+ hosts := []Host{}
+
+ c := pool.Get()
+ defer c.Close()
+
+ j, err := redis.String(c.Do("GET", cache_prefix+"database"))
+ if err == nil {
+ err = json.Unmarshal([]byte(j), &hosts)
+ if err != nil {
+ log.Println("Error JSON decoding: ", err)
+ Db.Find(&hosts)
+ }
+ } else {
+ log.Println("Redis: ", err)
+ Db.Find(&hosts)
+ }
+
+ index := mainTempl.Lookup("index.html")
-/*
-func StaticHandler(w http.ResponseWrite, r *http.Request) {
+ err = index.ExecuteTemplate(w, "index.html", hosts)
+ if err != nil {
+ log.Panic(err)
+ }
}
-*/
func RegisterHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Processing registration!")