diff --git a/controllers/static.go b/controllers/static.go index fe88011..ed0e68b 100644 --- a/controllers/static.go +++ b/controllers/static.go @@ -18,3 +18,31 @@ func StaticTemplate(templatePath string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { tpl.Execute(w, nil) } } + +func FAQ(templatePath string) http.HandlerFunc { + questions := []struct { + Question string + Answer string + }{ + { + Question: "Is this a real website?", + Answer: "No.", + }, + { + Question: "I Can Has Cheezburger?", + Answer: "No.", + }, + } + + tpl := views.Must(views.FromFS(templates.FS, templatePath)) + + var testWriter strings.Builder + err := tpl.ExecuteWriter(&testWriter, nil) + if err != nil { + panic(err) + } + + return func(w http.ResponseWriter, r *http.Request) { + tpl.Execute(w, questions) + } +} diff --git a/main.go b/main.go index 1c3e11d..2fb796d 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,7 @@ func main() { r.Use(middleware.Logger) r.Get("/", ctrlrs.StaticTemplate("home.gohtml")) r.Get("/contact", ctrlrs.StaticTemplate("contact.gohtml")) - r.Get("/faq", ctrlrs.StaticTemplate("faq.gohtml")) + r.Get("/faq", ctrlrs.FAQ("faq.gohtml")) r.NotFound(notFoundHandler) fmt.Println("Starting the server on :3000...") http.ListenAndServe(":3000", r) diff --git a/templates/faq.gohtml b/templates/faq.gohtml index 1919ba3..d103002 100644 --- a/templates/faq.gohtml +++ b/templates/faq.gohtml @@ -1,6 +1,10 @@
No.
-No.
+{{range .}} + {{template "qa" .}} +{{end}} + +{{define "qa"}} +{{.Answer}}
+{{end}}