aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-18 14:15:15 (UTC)
committerjan <jan@ruken.pw>2015-12-18 14:15:15 (UTC)
commitbdf4e9cc5c5934281631af09bf9a7d58719d0cbb (patch)
tree708429d7ed6fca2a0ab83d36d68fca05fa4ca958
parent2a27df2954e925ea17fd7d7dd7db787c1694e3b5 (diff)
kleiner renderer inklusive benutzung von charakterin.
-rw-r--r--README1
-rw-r--r--frontend/renderer.go33
-rw-r--r--main.go21
-rw-r--r--views/login.html10
4 files changed, 65 insertions, 0 deletions
diff --git a/README b/README
index e69de29..0f25db8 100644
--- a/README
+++ b/README
@@ -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 @@
1package frontend
2
3import (
4 "html/template"
5 "net/http"
6)
7
8// Renderer rendert Seiten.
9type Renderer struct {
10 templates *template.Template
11}
12
13// New erstellt einen neuen Renderer und sucht alle Templates aus dem gegebenen pfad.
14func 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.
23func (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.
31func (r *Renderer) RenderLoginPage(w http.ResponseWriter, data map[string]interface{}) {
32 r.RenderPage("login", w, data)
33}
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..cc4283c
--- /dev/null
+++ b/main.go
@@ -0,0 +1,21 @@
1package main
2
3import (
4 login "fagott.pw/charakterin"
5 "fagott.pw/grilist/frontend"
6 "github.com/julienschmidt/httprouter"
7 "log"
8 "net/http"
9)
10
11func 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