-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpages.go
42 lines (36 loc) · 1 KB
/
pages.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
package main
import (
"fmt"
"net/http"
)
type termPageParams struct {
Token string
Title string
}
func termPageHandler(token string, title string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
fmt.Printf("Token is being set to %s\n", token)
if err := termTemplate.Execute(w, termPageParams{Token: token, Title: title}); err != nil {
logger.Error(fmt.Sprintf("%s", err))
w.WriteHeader(http.StatusInternalServerError)
return
}
})
}
func replayPageHandler(token string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
if err := replayTemplate.Execute(w, termPageParams{Token: token}); err != nil {
logger.Error(fmt.Sprintf("%s", err))
w.WriteHeader(http.StatusInternalServerError)
return
}
})
}