-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (34 loc) · 750 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
39
40
41
42
43
44
45
46
package main
import (
"html/template"
"log"
"net/http"
)
var tmpl *template.Template
type Todo struct {
Item string
Done bool
}
type PageData struct {
Title string
Todos []Todo
}
func todo(w http.ResponseWriter, r *http.Request) {
data := PageData {
Title: "TODO List",
Todos: []Todo{
{Item: "Install GO", Done: true},
{Item: "Learn Go", Done: false},
{Item: "Like this video", Done: false},
},
}
tmpl.Execute(w, data)
}
func main() {
mux := http.NewServeMux()
tmpl = template.Must(template.ParseFiles("templates/index.gohtml"))
fs := http.FileServer(http.Dir("./static"))
mux.Handle("/static/", http.StripPrefix("/static/", fs))
mux.HandleFunc("/todo", todo)
log.Fatal(http.ListenAndServe(":9091", mux))
}