setup
This commit is contained in:
3
go.mod
Normal file
3
go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module gitea.sitodosi.com/betology/templates
|
||||||
|
|
||||||
|
go 1.21.6
|
||||||
10
layout.html
Normal file
10
layout.html
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<h1>{{.PageTitle}}</h1>
|
||||||
|
<ul>
|
||||||
|
{{range .Todos}}
|
||||||
|
{{if .Done}}
|
||||||
|
<li class="done">{{.Title}}</li>
|
||||||
|
{{else}}
|
||||||
|
<li>{{.Title}}</li>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
32
main.go
Normal file
32
main.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user