go-sample-webpage/main.go
2021-11-03 02:10:36 +01:00

42 lines
770 B
Go

package main
import (
"embed"
"gin-test/pkg/sample"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/unrolled/render"
)
// content holds our static web server content.
//go:embed static/* templates/*
var webserver embed.FS
func main() {
r := chi.NewRouter()
render := render.New(render.Options{
FileSystem: &render.EmbedFileSystem{
FS: webserver,
},
})
r.Use(middleware.Logger)
r.Handle("/static/*", http.FileServer(http.FS(webserver)))
r.Group(func(r chi.Router) {
r.Use(TemplateMiddelware)
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
render.HTML(w, http.StatusOK, "index", map[string]string {"title": "Soeren"})
})
sample.Register(r)
})
http.ListenAndServe(":3000", r)
}