-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (29 loc) · 853 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
37
38
package main
import (
"fmt"
"html/template"
"net/http"
)
var tpl *template.Template
func init() {
tpl = template.Must(template.ParseGlob("templates/*"))
}
func main() {
http.HandleFunc("/", foo)
http.HandleFunc("/bar", bar)
http.HandleFunc("/barred", barred)
http.Handle("/favicon.ico", http.NotFoundHandler())
http.ListenAndServe(":8080", nil)
}
func foo(w http.ResponseWriter, req *http.Request) {
fmt.Println("Your request method at foo : ", req.Method, "\n\n")
tpl.ExecuteTemplate(w, "bar.html", nil)
}
func bar(w http.ResponseWriter, req *http.Request) {
fmt.Println("Your request method at bar : ", req.Method)
http.Redirect(w, req, "/", http.StatusSeeOther)
}
func barred(w http.ResponseWriter, req *http.Request) {
fmt.Println("Your request method at barred : ", req.Method)
tpl.ExecuteTemplate(w, "index.gohtml", nil)
}