Displaying server data in templates
This commit is contained in:
14
main.go
14
main.go
@@ -7,12 +7,24 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
type Film struct {
|
||||
Title string
|
||||
Director string
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("hello world")
|
||||
|
||||
h1 := func(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl := template.Must(template.ParseFiles("index.html"))
|
||||
tmpl.Execute(w, nil)
|
||||
films := map[string][]Film{
|
||||
"Films": {
|
||||
{Title: "The Goodfather", Director: "Francis Ford Coppola"},
|
||||
{Title: "Blade Runner", Director: "Ridley Scott"},
|
||||
{Title: "The Thing", Director: "John Carpenter"},
|
||||
},
|
||||
}
|
||||
tmpl.Execute(w, films)
|
||||
}
|
||||
|
||||
http.HandleFunc("/", h1)
|
||||
|
||||
Reference in New Issue
Block a user