Compare commits

..

2 Commits

Author SHA1 Message Date
spsobole 377fcd0230 Sync versions of core 2024-04-16 11:54:34 -06:00
spsobole 1cfae5917e Add default name to logger 2024-04-16 11:35:00 -06:00
3 changed files with 14 additions and 10 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module git.twelvetwelve.org/library/snap
go 1.20 go 1.20
require ( require (
git.twelvetwelve.org/library/core v0.1.1-0.20240416170915-b309a62d2748 git.twelvetwelve.org/library/core v0.2.0
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.0
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
) )

6
go.sum
View File

@ -1,7 +1,5 @@
git.twelvetwelve.org/library/core v0.0.0-20230519041221-8f2da7be661d h1:vZy7QM4kcGzbscnY1pSOGNDBDZMmhis/Z+9kZ70gD8Q= git.twelvetwelve.org/library/core v0.2.0 h1:ieCtwuwAhla/h/NZwm0NZwIPkC285dsas64/6nlPRY0=
git.twelvetwelve.org/library/core v0.0.0-20230519041221-8f2da7be661d/go.mod h1:QSIAU+Arcx8nd7p4e3hFQIqi50cYf9I0KW9sqxkFnMY= git.twelvetwelve.org/library/core v0.2.0/go.mod h1:D95+y6AdDBvviXryconVQdgDzxCaLCjq6gi3YknBgp0=
git.twelvetwelve.org/library/core v0.1.1-0.20240416170915-b309a62d2748 h1:/rkWOGgiJxOf9mo9/x7Vw2aCHwCUIoaIa2xWxZo4o18=
git.twelvetwelve.org/library/core v0.1.1-0.20240416170915-b309a62d2748/go.mod h1:D95+y6AdDBvviXryconVQdgDzxCaLCjq6gi3YknBgp0=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=

View File

@ -23,6 +23,7 @@ import (
) )
type Server struct { type Server struct {
log log.Logger
address string address string
theme string theme string
debug bool debug bool
@ -211,7 +212,7 @@ func (s *Server) LoadTemplatesFS(fs http.FileSystem, base string) (*template.Tem
if strings.Contains(path, ".html") { if strings.Contains(path, ".html") {
_, err := s.parseTemplates(tmpl, path) _, err := s.parseTemplates(tmpl, path)
if err != nil { if err != nil {
log.Printf("%+v\n", err) s.log.Printf("%+v\n", err)
} }
} }
return err return err
@ -227,7 +228,7 @@ func (s *Server) LoadTemplatesFS(fs http.FileSystem, base string) (*template.Tem
func (s *Server) loadTemplates() *template.Template { func (s *Server) loadTemplates() *template.Template {
tmpl, err := s.LoadTemplatesFS(s.fs, s.templates) tmpl, err := s.LoadTemplatesFS(s.fs, s.templates)
if err != nil { if err != nil {
log.Fatalf("loadTemplates %v %v\n", err, s.templates) s.log.Fatalf("loadTemplates %v %v\n", err, s.templates)
} }
return tmpl return tmpl
} }
@ -254,7 +255,7 @@ func (s *Server) render(w http.ResponseWriter, tmpl string, content interface{})
} }
err := s.getTemplates().ExecuteTemplate(w, tmpl, content) err := s.getTemplates().ExecuteTemplate(w, tmpl, content)
if err != nil { if err != nil {
log.Warnf("%s\n", err) s.log.Warnf("%s\n", err)
} }
} }
@ -284,7 +285,7 @@ func (s *Server) HandleFuncAuthenticatedWithLogin(path string, loginHandler func
func (s *Server) HandleFuncCustomAuth(auth auth.Authenticator, path, redirect string, f func(c *Context)) *mux.Route { func (s *Server) HandleFuncCustomAuth(auth auth.Authenticator, path, redirect string, f func(c *Context)) *mux.Route {
if auth == nil { if auth == nil {
log.Warnf("Nil auth on %s\n", path) s.log.Warnf("Nil auth on %s\n", path)
return nil return nil
} }
return s.router.HandleFunc(path, s.authenticated(auth, redirect, f)) return s.router.HandleFunc(path, s.authenticated(auth, redirect, f))
@ -320,7 +321,7 @@ func (s *Server) Router() *mux.Router {
func (s *Server) ServeTLS(keyPath string, certPath string) error { func (s *Server) ServeTLS(keyPath string, certPath string) error {
kpr, err := autocert.NewManager(certPath, keyPath) kpr, err := autocert.NewManager(certPath, keyPath)
if err != nil { if err != nil {
log.Fatalf("%v\n", err) s.log.Fatalf("%v\n", err)
} }
s.http = &http.Server{ s.http = &http.Server{
@ -422,6 +423,10 @@ func (s *Server) WithHealthCheck(version, date string, status func() (bool, stri
}) })
} }
func (s *Server) SetLogger(logger log.Logger) {
s.log = logger
}
func (s *Server) Dump() { func (s *Server) Dump() {
fmt.Printf(" Theme: %s\n", s.theme) fmt.Printf(" Theme: %s\n", s.theme)
fmt.Printf(" Templates: %s\n", s.templates) fmt.Printf(" Templates: %s\n", s.templates)
@ -443,6 +448,7 @@ func New(address string, path string, auth auth.Authenticator) *Server {
templateFuncs: builtinFuncMap, templateFuncs: builtinFuncMap,
theme: "/static/css/default.css", theme: "/static/css/default.css",
meta: make(map[string]string), meta: make(map[string]string),
log: log.WithName("SNAP"),
} }
return &s return &s
} }