diff options
Diffstat (limited to 'app/handler.go')
| -rw-r--r-- | app/handler.go | 32 |
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!") |
