Files
PriceForge/bible-local/kit/scaffolds/go-nethttp-web/internal/web/server.go.tmpl
2026-03-01 22:26:50 +03:00

38 lines
692 B
Cheetah

package web
import (
"html/template"
"io/fs"
"net/http"
appweb "{{ .module_path }}/web"
)
type Server struct {
mux *http.ServeMux
tmpl *template.Template
}
func NewServer() (*Server, error) {
tmpl, err := parseTemplates()
if err != nil {
return nil, err
}
s := &Server{
mux: http.NewServeMux(),
tmpl: tmpl,
}
s.registerRoutes()
return s, nil
}
func (s *Server) Handler() http.Handler { return s.mux }
func (s *Server) registerRoutes() {
s.mux.HandleFunc("/", s.handleIndex)
s.mux.HandleFunc("/healthz", s.handleHealthz)
staticFS, _ := fs.Sub(appweb.Assets, "static")
s.mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticFS))))
}