Vikunja and NTFY. #1

Open
pztrn wants to merge 1 commits from pztrn/vikunja-and-ntfy into main
4 changed files with 21 additions and 15 deletions
Showing only changes of commit 7cc06a9ef1 - Show all commits
+2
View File
@@ -1,3 +1,5 @@
module go.dev.pztrn.name/vikunja-notifier
go 1.26.3
require github.com/felixge/httpsnoop v1.0.4
+2
View File
@@ -0,0 +1,2 @@
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
@@ -3,22 +3,24 @@ package httpserver
import (
"fmt"
"net/http"
"time"
"github.com/felixge/httpsnoop"
)
func (h *httpServer) requestLoggingMiddleware(fn http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
startTime := time.Now()
fn(w, r)
return func(w http.ResponseWriter, req *http.Request) {
metrics := httpsnoop.CaptureMetrics(fn, w, req)
h.logger.Info(
"HTTP request.",
"remote_addr", r.RemoteAddr,
"user_agent", r.UserAgent(),
"host", r.Host,
"path", fmt.Sprintf("%s %s", r.Method, r.RequestURI),
"duration", time.Since(startTime),
"remote_addr", req.RemoteAddr,
"user_agent", req.UserAgent(),
"host", req.Host,
"path", fmt.Sprintf("%s %s", req.Method, req.RequestURI),
"duration", metrics.Duration,
"req_size", req.ContentLength,
"resp_size", metrics.Written,
"http_code", metrics.Code,
)
}
}
+1 -1
View File
@@ -49,12 +49,12 @@ func (h *httpServer) configureHTTPServer() error {
}
func (h *httpServer) RegisterHandler(method, path string, handler http.HandlerFunc) {
h.httpMux.HandleFunc(fmt.Sprintf("%s %s", method, path), func(w http.ResponseWriter, r *http.Request) {
//nolint:modernize
for i := len(h.middlewares) - 1; i >= 0; i-- {
handler = h.middlewares[i](handler)
}
h.httpMux.HandleFunc(fmt.Sprintf("%s %s", method, path), func(w http.ResponseWriter, r *http.Request) {
handler(w, r)
})
}