-
Notifications
You must be signed in to change notification settings - Fork 43
/
templates.go
36 lines (30 loc) · 901 Bytes
/
templates.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
package templates
import (
"html/template"
"log"
"net/http"
)
// LoginPage : the login page
type LoginPage struct {
BAlertUser bool
AlertMsg string
}
// RegisterPage : the register page
type RegisterPage struct {
BAlertUser bool
AlertMsg string
}
// RestrictedPage : the restricted page
type RestrictedPage struct {
CsrfSecret string
SecretMessage string
}
var templates = template.Must(template.ParseFiles("./server/templates/templateFiles/login.tmpl", "./server/templates/templateFiles/register.tmpl", "./server/templates/templateFiles/restricted.tmpl"))
// RenderTemplate : apply the given template to the response writer
func RenderTemplate(w http.ResponseWriter, tmpl string, p interface{}) {
err := templates.ExecuteTemplate(w, tmpl+".tmpl", p)
if err != nil {
log.Printf("Temlate error here: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}