go-sample-webpage/pkg/dashboard/dashboard.go

32 lines
661 B
Go
Raw Normal View History

2021-11-25 00:32:48 +00:00
package dashboard
import (
"embed"
"github.com/go-chi/chi/v5"
"github.com/unrolled/render"
"net/http"
)
// content holds our static web server content.
//go:embed templates/*
var webserver embed.FS
var ren *render.Render
func Register(router chi.Router, template func(http.Handler) http.Handler) {
ren = render.New(render.Options{
//Layout: "layout",
FileSystem: &render.EmbedFileSystem{
FS: webserver,
},
})
router.Group(func(r chi.Router) {
r.Use(template)
r.Get("/dashboard", sampleCall)
})
}
func sampleCall(w http.ResponseWriter, r *http.Request) {
ren.HTML(w, http.StatusOK, "dashboard", map[string]string {"title": "World"})
}