rewrite to using new method
This commit is contained in:
@@ -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
12
middleware/headers.go
Normal 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)
|
||||
})
|
||||
}
|
||||
@@ -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))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user