38 lines
692 B
Cheetah
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))))
|
|
}
|
|
|