go-blocks/example/main.go
2024-08-21 22:39:00 +02:00

38 lines
681 B
Go

package main
import (
"fmt"
"net/http"
"text/template"
"github.com/zepyrshut/gorender"
)
func dummyFunc() string {
return "dummy function"
}
func main() {
newFuncs := template.FuncMap{
"dummyFunc": dummyFunc,
}
renderOpts := &gorender.Render{
EnableCache: true,
TemplatesPath: "template",
PageTemplatesPath: "template/pages",
Functions: newFuncs,
}
ren := gorender.New(gorender.WithRenderOptions(renderOpts))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
td := &gorender.TemplateData{}
ren.Template(w, r, "page.html", td)
})
fmt.Println("Server running on port 8080")
http.ListenAndServe(":8080", nil)
}