-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.go
64 lines (50 loc) · 1.46 KB
/
hello.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package hello
import (
"html/template"
"net/http"
)
func init() {
http.HandleFunc("/", home)
http.HandleFunc("/posts", posts)
http.HandleFunc("/single", single)
}
func home(w http.ResponseWriter, r *http.Request) {
d := map[string]interface{}{"Titulo": "GDG Monterrey", "Tab" : 0}
t, err := template.ParseFiles("templates/root.html", "templates/base.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else{
err := t.ExecuteTemplate(w,"base", d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
type Site struct {
Titulo string
Tab int
}
func posts(w http.ResponseWriter, r *http.Request) {
d := Site {Titulo:"GDG Monterrey", Tab: 1}
t, err := template.ParseFiles("templates/posts.html", "templates/base.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else{
err := t.ExecuteTemplate(w,"base", d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
func single(w http.ResponseWriter, r *http.Request) {
d := Site {Titulo:"GDG Monterrey", Tab: 1}
t, err := template.ParseFiles("templates/single.html");
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
err := t.Execute(w, d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}