-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
42 lines (36 loc) · 755 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
package main
import (
"fmt"
"html/template"
"log"
"net/http"
)
// Todo list of activity
type Todo struct {
Title string
Done bool
}
// TodoPageData list of page
type TodoPageData struct {
PageTitle string
Todos []Todo
}
func main() {
tmpl := template.Must(template.ParseFiles("layout.html"))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := TodoPageData{
PageTitle: "My TODO list",
Todos: []Todo{
{Title: "Task 1 is here", Done: false},
{Title: "Task 2", Done: true},
{Title: "Task 3 last", Done: true},
},
}
tmpl.Execute(w, data)
})
fmt.Println("Listening on localhost:8080")
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}