diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..af60e4c --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module gitea.sitodosi.com/betology/templates + +go 1.21.6 diff --git a/layout.html b/layout.html new file mode 100644 index 0000000..ebbc80d --- /dev/null +++ b/layout.html @@ -0,0 +1,10 @@ +

{{.PageTitle}}

+ \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..00ed92f --- /dev/null +++ b/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "html/template" + "net/http" +) + +type Todo struct { + Title string + Done bool +} + +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", Done: false}, + {Title: "Task 2", Done: true}, + {Title: "Task 3", Done: true}, + }, + } + tmpl.Execute(w, data) + }) + http.ListenAndServe(":8000", nil) +} diff --git a/templates b/templates new file mode 100755 index 0000000..9b8c06e Binary files /dev/null and b/templates differ