This repository has been archived by the owner on May 25, 2018. It is now read-only.
/
controllers.go
47 lines (41 loc) · 1.58 KB
/
controllers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package controllers
import (
"net/http"
"github.com/goffee/goffee/Godeps/_workspace/src/github.com/zenazn/goji/web"
"github.com/goffee/goffee/web/render"
)
func renderError(c web.C, w http.ResponseWriter, req *http.Request, message string, status int) {
templates := render.GetBaseTemplates()
templates = append(templates, "web/views/error.html")
err := render.Template(c, w, req, templates, "layout", map[string]interface{}{"Status": status, "Message": message})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
// Home serves the home page
func Home(c web.C, w http.ResponseWriter, req *http.Request) {
templates := render.GetBaseTemplates()
templates = append(templates, "web/views/home.html")
err := render.Template(c, w, req, templates, "layout", map[string]interface{}{})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
// About serves the about page
func About(c web.C, w http.ResponseWriter, req *http.Request) {
templates := render.GetBaseTemplates()
templates = append(templates, "web/views/about.html")
err := render.Template(c, w, req, templates, "layout", map[string]interface{}{})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
// NotFound serves the 404 page
func NotFound(c web.C, w http.ResponseWriter, req *http.Request) {
templates := render.GetBaseTemplates()
templates = append(templates, "web/views/404.html")
err := render.Template(c, w, req, templates, "layout", map[string]interface{}{})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}