package main import ( "fmt" "net/http" "strings" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "git.kealoha.me/lks/lenslocked/templates" "git.kealoha.me/lks/lenslocked/views" ) func parseStaticTemplate(templatePath string) http.HandlerFunc { 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, nil) } } func notFoundHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf8") w.WriteHeader(http.StatusNotFound) fmt.Fprint(w, "404 page not found") } func main() { r := chi.NewRouter() r.Use(middleware.Logger) r.Get("/", parseStaticTemplate("home.gohtml")) r.Get("/contact", parseStaticTemplate("contact.gohtml")) r.Get("/faq", parseStaticTemplate("faq.gohtml")) r.NotFound(notFoundHandler) fmt.Println("Starting the server on :3000...") http.ListenAndServe(":3000", r) }