rewrite to using new method

This commit is contained in:
2024-06-16 18:21:06 -05:00
parent f07bd666fb
commit 790c8c969a
19 changed files with 388 additions and 395 deletions

View File

@@ -1,17 +0,0 @@
package middleware
import (
"net/http"
"strings"
)
func EnsureAdmin(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !strings.Contains(r.Header.Get("Authorization"), "Admin") {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(http.StatusText(http.StatusUnauthorized)))
return
}
next.ServeHTTP(w, r)
})
}

12
middleware/headers.go Normal file
View File

@@ -0,0 +1,12 @@
package middleware
import "net/http"
func Headers(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
next.ServeHTTP(w, r)
})
}

View File

@@ -1,7 +1,7 @@
package middleware
import (
"log/slog"
"log"
"net/http"
"time"
)
@@ -27,13 +27,13 @@ func Logging(next http.Handler) http.Handler {
next.ServeHTTP(wrapped, r)
slog.Info(
"Health Check",
slog.Int("Method", wrapped.statusCode),
r.Method,
r.URL.Path,
slog.String("time", time.Since(start).String()),
)
// log.Println("INFO", wrapped.statusCode, r.Method, r.URL.Path, time.Since(start))
//slog.Info(
// "Health Check",
// slog.Int("Method", wrapped.statusCode),
// r.Method,
// r.URL.Path,
// slog.String("time", time.Since(start).String()),
//)
log.Println("INFO", wrapped.statusCode, r.Method, r.URL.Path, time.Since(start))
})
}