diff options
author | jan <jan@ruken.pw> | 2015-12-18 14:15:15 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2015-12-18 14:15:15 (UTC) |
commit | bdf4e9cc5c5934281631af09bf9a7d58719d0cbb (patch) | |
tree | 708429d7ed6fca2a0ab83d36d68fca05fa4ca958 | |
parent | 2a27df2954e925ea17fd7d7dd7db787c1694e3b5 (diff) |
kleiner renderer inklusive benutzung von charakterin.
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | frontend/renderer.go | 33 | ||||
-rw-r--r-- | main.go | 21 | ||||
-rw-r--r-- | views/login.html | 10 |
4 files changed, 65 insertions, 0 deletions
@@ -0,0 +1 @@ | |||
Grilist ist eine Liste. für Grils. \ No newline at end of file | |||
diff --git a/frontend/renderer.go b/frontend/renderer.go new file mode 100644 index 0000000..5673860 --- /dev/null +++ b/frontend/renderer.go | |||
@@ -0,0 +1,33 @@ | |||
1 | package frontend | ||
2 | |||
3 | import ( | ||
4 | "html/template" | ||
5 | "net/http" | ||
6 | ) | ||
7 | |||
8 | // Renderer rendert Seiten. | ||
9 | type Renderer struct { | ||
10 | templates *template.Template | ||
11 | } | ||
12 | |||
13 | // New erstellt einen neuen Renderer und sucht alle Templates aus dem gegebenen pfad. | ||
14 | func New(path string) *Renderer { | ||
15 | r := &Renderer{ | ||
16 | template.Must(template.ParseGlob(path + "/*")), | ||
17 | } | ||
18 | |||
19 | return r | ||
20 | } | ||
21 | |||
22 | // RenderPage rendert eine bestimmte Seite (basierend auf dem Template-Namen) und den gegebenen Daten. | ||
23 | func (r *Renderer) RenderPage(name string, w http.ResponseWriter, data map[string]interface{}) { | ||
24 | err := r.templates.ExecuteTemplate(w, name, data) | ||
25 | if err != nil { | ||
26 | http.Error(w, err.Error(), http.StatusInternalServerError) | ||
27 | } | ||
28 | } | ||
29 | |||
30 | // RenderLoginPage zeigt die Loginseite an. | ||
31 | func (r *Renderer) RenderLoginPage(w http.ResponseWriter, data map[string]interface{}) { | ||
32 | r.RenderPage("login", w, data) | ||
33 | } | ||
@@ -0,0 +1,21 @@ | |||
1 | package main | ||
2 | |||
3 | import ( | ||
4 | login "fagott.pw/charakterin" | ||
5 | "fagott.pw/grilist/frontend" | ||
6 | "github.com/julienschmidt/httprouter" | ||
7 | "log" | ||
8 | "net/http" | ||
9 | ) | ||
10 | |||
11 | func main() { | ||
12 | frontend := frontend.New("views") | ||
13 | charakterin := login.New() | ||
14 | charakterin.UseRenderer(frontend) | ||
15 | |||
16 | router := httprouter.New() | ||
17 | router.HandlerFunc("GET", "/login", charakterin.DisplayLogin) | ||
18 | router.HandlerFunc("POST", "/login", charakterin.Login) | ||
19 | |||
20 | log.Fatal(http.ListenAndServe(":8080", router)) | ||
21 | } | ||
diff --git a/views/login.html b/views/login.html new file mode 100644 index 0000000..934d575 --- /dev/null +++ b/views/login.html | |||
@@ -0,0 +1,10 @@ | |||
1 | {{ define "login" }} | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>Grilist - Login</title> | ||
5 | </head> | ||
6 | <body> | ||
7 | Benis. | ||
8 | </body> | ||
9 | </html> | ||
10 | {{ end }} \ No newline at end of file | ||