From 673a0c26cdd063122d5bdc2e342ca0f6da146054 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 19 Feb 2024 12:08:07 -0500 Subject: [PATCH] bump --- go.mod | 1 + go.sum | 2 ++ main.go | 23 ++++++++++++++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 32022fb..57f9061 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( git.teamworkapps.com/shortcut/forms v0.0.0-20240202203738-c42dc9446449 // indirect github.com/emersion/go-message v0.18.0 // indirect github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594 // indirect + github.com/gorilla/mux v1.8.1 // indirect github.com/knadh/go-pop3 v0.3.0 // indirect github.com/shopspring/decimal v1.3.1 // indirect ) diff --git a/go.sum b/go.sum index 9aa734c..380689a 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/emersion/go-message v0.18.0 h1:7LxAXHRpSeoO/Wom3ZApVZYG7c3d17yCScYce8 github.com/emersion/go-message v0.18.0/go.mod h1:Zi69ACvzaoV/MBnrxfVBPV3xWEuCmC2nEN39oJF4B8A= github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594 h1:IbFBtwoTQyw0fIM5xv1HF+Y+3ZijDR839WMulgxCcUY= github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/knadh/go-pop3 v0.3.0 h1:h6wh28lyT/vUBMSiSwDDUXZjHH6zL8CM8WYCPbETM4Y= github.com/knadh/go-pop3 v0.3.0/go.mod h1:a5kUJzrBB6kec+tNJl+3Z64ROgByKBdcyub+mhZMAfI= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= diff --git a/main.go b/main.go index 486fc39..a4fff27 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,8 @@ import ( "text/template" "time" + "github.com/gorilla/mux" + "git.teamworkapps.com/shortcut/forms" "github.com/knadh/go-pop3" ) @@ -19,6 +21,15 @@ type tplData struct { Body string } +func mwLog(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + log.Printf("%s %s", r.RemoteAddr, r.URL.String()) + next.ServeHTTP(w, r) + }) +} + + + func main() { forms.GlobalStyles.ContainerClasses = "w-full bg-gray-100 justify-center py-6 rounded-lg shadow flex" @@ -74,13 +85,15 @@ func main() { } var d tplData - s := http.NewServeMux() - s.HandleFunc("style.css", http.FileServer(http.Dir("./")).ServeHTTP) - s.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + r := mux.NewRouter() + r.Use(mwLog) + + r.HandleFunc("/style.css", http.FileServer(http.Dir("./")).ServeHTTP) + r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { d.Body = f.Render(true) tmpl.Execute(w, d) }) - s.HandleFunc("/changepassword", func(w http.ResponseWriter, r *http.Request) { + r.HandleFunc("/changepassword", func(w http.ResponseWriter, r *http.Request) { if f.Validate(r) != nil { d.Body = f.Render(true) tmpl.Execute(w, d) @@ -111,5 +124,5 @@ func main() { d.Time = time.Now().Unix() d.Body = f.Render(true) tmpl.Execute(os.Stdout, d) - http.ListenAndServe(":8910", s) + http.ListenAndServe(":8910", r) }