/
main.go
36 lines (30 loc) · 903 Bytes
/
main.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 main
import (
"github.com/julienschmidt/httprouter"
"html/template"
"net/http"
)
var tpl *template.Template
func init() {
r := httprouter.New()
http.Handle("/", r)
r.GET("/", Home)
r.GET("/login", Login)
r.GET("/signup", Signup)
http.Handle("/favicon.ico", http.NotFoundHandler())
http.Handle("/public/", http.StripPrefix("/public", http.FileServer(http.Dir("public/"))))
tpl = template.Must(template.ParseGlob("templates/html/*.html"))
}
func Home(res http.ResponseWriter, req *http.Request, _ httprouter.Params) {
if req.URL.Path != "/" {
http.NotFound(res, req)
return
}
tpl.ExecuteTemplate(res, "home.html", nil)
}
func Login(res http.ResponseWriter, req *http.Request, _ httprouter.Params) {
tpl.ExecuteTemplate(res, "login.html", nil)
}
func Signup(res http.ResponseWriter, req *http.Request, _ httprouter.Params) {
tpl.ExecuteTemplate(res, "signup.html", nil)
}