From 97716e724736f0bc8c50a721c84a8edafce84670 Mon Sep 17 00:00:00 2001 From: spsobole Date: Tue, 23 May 2023 08:09:57 -0600 Subject: [PATCH] Update post move --- README.md | 4 ++-- auth/noauth.go | 2 +- auth/token.go | 2 +- build.yaml | 4 ++-- context.go | 2 +- examples/simple/main.go | 4 ++-- go.mod | 12 +++++++++--- go.sum | 5 ++--- route.go | 2 +- server.go | 31 ++++++++++++++++--------------- server_test.go | 2 +- 11 files changed, 38 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 6b8a3b6..12a346d 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Typical layout for snap servers package main import ( - "git.thirdmartini.com/pub/snap" - "git.thirdmartini.com/pub/snap/auth" + "git.twelvetwelve.org/library/snap" + "git.twelvetwelve.org/library/snap/auth" ) func handler(c *snap.Context) { diff --git a/auth/noauth.go b/auth/noauth.go index 58f6e11..a6ba826 100644 --- a/auth/noauth.go +++ b/auth/noauth.go @@ -2,7 +2,7 @@ package auth import "net/http" -//---------------------------------------------------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------------------------------------- type NoAuth struct { User AuthData } diff --git a/auth/token.go b/auth/token.go index 38c0a57..9251df7 100644 --- a/auth/token.go +++ b/auth/token.go @@ -2,7 +2,7 @@ package auth import "net/http" -//---------------------------------------------------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------------------------------------- type TokenAuth struct { users map[string]TokenUser } diff --git a/build.yaml b/build.yaml index f55205c..15a4003 100644 --- a/build.yaml +++ b/build.yaml @@ -13,7 +13,7 @@ jobs: format: - name: Format source code type: golang - source: git.thirdmartini.com/pub/snap/... + source: git.twelvetwelve.org/library/snap/... options: flags: @@ -22,6 +22,6 @@ jobs: test: - name: Running unit tests type: golang - source: git.thirdmartini.com/pub/snap/... + source: git.twelvetwelve.org/library/snap/... options: flags: diff --git a/context.go b/context.go index c0d3d43..0f46404 100644 --- a/context.go +++ b/context.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - "git.thirdmartini.com/pub/snap/auth" + "git.twelvetwelve.org/library/snap/auth" ) type Context struct { diff --git a/examples/simple/main.go b/examples/simple/main.go index b239e80..f99d456 100644 --- a/examples/simple/main.go +++ b/examples/simple/main.go @@ -1,8 +1,8 @@ package main import ( - "git.thirdmartini.com/pub/snap" - "git.thirdmartini.com/pub/snap/auth" + "git.twelvetwelve.org/library/snap" + "git.twelvetwelve.org/library/snap/auth" ) func handler(c *snap.Context) { diff --git a/go.mod b/go.mod index 9f62527..4400087 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,15 @@ -module git.thirdmartini.com/pub/snap +module git.twelvetwelve.org/library/snap -go 1.15 +go 1.20 require ( - git.thirdmartini.com/pub/fancylog v0.0.0-20180118031448-3f3ebedd6016 github.com/gorilla/mux v1.8.0 github.com/stretchr/testify v1.7.0 ) + +require ( + git.twelvetwelve.org/library/core v0.0.0-20230519041221-8f2da7be661d // indirect + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +) diff --git a/go.sum b/go.sum index 818e77b..6aa0014 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,11 @@ -git.thirdmartini.com/pub/fancylog v0.0.0-20180118031448-3f3ebedd6016 h1:egW0VTyAgD7FjG6iZKHBcHc7siCGjoxm1T71GecYUE4= -git.thirdmartini.com/pub/fancylog v0.0.0-20180118031448-3f3ebedd6016/go.mod h1:nxr8UYB5P+7cpJPpqcbhMjfqm+GH3VDZQs2dFWibA68= +git.twelvetwelve.org/library/core v0.0.0-20230519041221-8f2da7be661d h1:vZy7QM4kcGzbscnY1pSOGNDBDZMmhis/Z+9kZ70gD8Q= +git.twelvetwelve.org/library/core v0.0.0-20230519041221-8f2da7be661d/go.mod h1:QSIAU+Arcx8nd7p4e3hFQIqi50cYf9I0KW9sqxkFnMY= 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/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= diff --git a/route.go b/route.go index 54237d8..dfc408f 100644 --- a/route.go +++ b/route.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "git.thirdmartini.com/pub/snap/auth" + "git.twelvetwelve.org/library/snap/auth" ) type RouteBuilder struct { diff --git a/server.go b/server.go index 587d55d..20b8887 100644 --- a/server.go +++ b/server.go @@ -13,12 +13,12 @@ import ( "strings" "time" - "git.thirdmartini.com/pub/snap/pkg/autocert" + "git.twelvetwelve.org/library/core/log" + + "git.twelvetwelve.org/library/snap/pkg/autocert" "github.com/gorilla/mux" - "git.thirdmartini.com/pub/fancylog" - - "git.thirdmartini.com/pub/snap/auth" + "git.twelvetwelve.org/library/snap/auth" ) type Server struct { @@ -65,11 +65,11 @@ func (s *Server) makeContext(auth *auth.AuthData, w http.ResponseWriter, r *http func (s *Server) withLoginHandler(auth auth.Authenticator, loginHandler func(c *Context) bool, handle func(c *Context)) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if s.debug { - log.Debug("authenticated request with login ui handler: ", r.RequestURI) + log.Debugf("authenticated request with login ui handler: %s\n", r.RequestURI) } rec, ok := auth.DoAuth(w, r) if !ok { - log.Debug("authenticated request with login ui handler to login ", r.RequestURI) + log.Debugf("authenticated request with login ui handler to login %s\n", r.RequestURI) c := s.makeContext(rec, w, r) if loginHandler(c) { handle(c) @@ -84,7 +84,7 @@ func (s *Server) withLoginHandler(auth auth.Authenticator, loginHandler func(c * func (s *Server) authenticated(auth auth.Authenticator, redirect string, handle func(c *Context)) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if s.debug { - log.Debug("authenticated request: ", r.RequestURI) + log.Debugf("authenticated request: %s\n", r.RequestURI) } rec, ok := auth.DoAuth(w, r) @@ -104,7 +104,7 @@ func (s *Server) authenticated(auth auth.Authenticator, redirect string, handle func (s *Server) wrapper(handle func(c *Context)) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if s.debug { - log.Debug("request: ", r.RequestURI) + log.Debugf("request: %s", r.RequestURI) } c := s.makeContext(nil, w, r) @@ -121,8 +121,9 @@ func (s *Server) wrapper(handle func(c *Context)) http.HandlerFunc { } // This is a bit different then the standard template.parseFiles code in that it gives us hiarchial templates -// header.html -// mydirectory/service.html ... +// +// header.html +// mydirectory/service.html ... func (s *Server) parseTemplates(t *template.Template, filenames ...string) (*template.Template, error) { //if err := t.checkCanParse(); err != nil { // return nil, err @@ -206,7 +207,7 @@ func (s *Server) LoadTemplatesFS(fs http.FileSystem, base string) (*template.Tem if strings.Contains(path, ".html") { _, err := s.parseTemplates(tmpl, path) if err != nil { - log.Println(err) + log.Printf("%+v\n", err) } } return err @@ -222,7 +223,7 @@ func (s *Server) LoadTemplatesFS(fs http.FileSystem, base string) (*template.Tem func (s *Server) loadTemplates() *template.Template { tmpl, err := s.LoadTemplatesFS(s.fs, s.templates) if err != nil { - log.Fatal("loadTemplates", err, s.templates) + log.Fatalf("loadTemplates %v %v\n", err, s.templates) } return tmpl } @@ -249,7 +250,7 @@ func (s *Server) render(w http.ResponseWriter, tmpl string, content interface{}) } err := s.getTemplates().ExecuteTemplate(w, tmpl, content) if err != nil { - log.Warn(err) + log.Warnf("%s\n", err) } } @@ -279,7 +280,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 { if auth == nil { - log.Warn("Nil auth on", path) + log.Warnf("Nil auth on %s\n", path) return nil } return s.router.HandleFunc(path, s.authenticated(auth, redirect, f)) @@ -315,7 +316,7 @@ func (s *Server) Router() *mux.Router { func (s *Server) ServeTLS(keyPath string, certPath string) error { kpr, err := autocert.NewManager(certPath, keyPath) if err != nil { - log.Fatal(err) + log.Fatalf("%v\n", err) } srv := &http.Server{ diff --git a/server_test.go b/server_test.go index 6f0fa77..e4e3a25 100644 --- a/server_test.go +++ b/server_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" - "git.thirdmartini.com/pub/snap/auth" + "git.twelvetwelve.org/library/snap/auth" ) var rootExpected = []byte(`