-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.go
63 lines (51 loc) · 1.21 KB
/
handlers.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
package main
import (
"html/template"
"net/http"
"github.com/julienschmidt/httprouter"
"log"
)
type HomePage struct {
Name string
}
type LivePage struct {
Name string
Url string
Type string
}
type VideoPage struct {
Name string
Url string
}
func homeHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
p := &HomePage{Name: "yyy"}
t, err := template.ParseFiles("./urls/home.html")
if err != nil {
log.Printf("Parsing template home.html error: %s", err)
return
}
t.Execute(w, p)
return
}
func liveHandler(writer http.ResponseWriter, request *http.Request, params httprouter.Params) {
lid := params.ByName("lid")
p := &LivePage{Name: "yyy"}
t, err := template.ParseFiles("./urls/" + lid + ".html")
if err != nil {
log.Printf("Parsing template home.html error: %s", err)
return
}
t.Execute(writer, p)
return
}
func videoHandler(writer http.ResponseWriter, request *http.Request, params httprouter.Params) {
vid := params.ByName("vid")
p := &VideoPage{Name: videoMap[vid].Name, Url: videoMap[vid].Url}
t, err := template.ParseFiles("./urls/videos.html")
if err != nil {
log.Printf("Parsing template home.html error: %s", err)
return
}
t.Execute(writer, p)
return
}