initial cognito
actual
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -62,6 +63,65 @@ type Server struct {
|
||||
cleanup func() error
|
||||
}
|
||||
|
||||
// Return a middleware that logs all of the cookies and headers for a request
|
||||
// if DEBUG=true is set in the environment.
|
||||
func getDebugMiddleware(logger *slog.Logger) echo.MiddlewareFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
// Only log if DEBUG=true
|
||||
if os.Getenv("DEBUG") != "true" {
|
||||
return next(c)
|
||||
}
|
||||
|
||||
req := c.Request()
|
||||
|
||||
// Create structured debug info
|
||||
debugInfo := map[string]interface{}{
|
||||
"method": req.Method,
|
||||
"url": map[string]interface{}{
|
||||
"full": req.URL.String(),
|
||||
"path": req.URL.Path,
|
||||
"query": req.URL.RawQuery,
|
||||
},
|
||||
"headers": map[string][]string{},
|
||||
"cookies": []map[string]string{},
|
||||
}
|
||||
|
||||
// Collect headers - Fix type assertion error checking
|
||||
headers, ok := debugInfo["headers"].(map[string][]string)
|
||||
if !ok {
|
||||
logger.Error("Failed to assert headers type")
|
||||
} else {
|
||||
for k, v := range req.Header {
|
||||
headers[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
// Collect cookies - Fix type assertion error checking
|
||||
cookies, ok := debugInfo["cookies"].([]map[string]string)
|
||||
if !ok {
|
||||
logger.Error("Failed to assert cookies type")
|
||||
} else {
|
||||
for _, cookie := range req.Cookies() {
|
||||
cookies = append(cookies, map[string]string{
|
||||
"name": cookie.Name,
|
||||
"value": cookie.Value,
|
||||
})
|
||||
}
|
||||
// Update the slice in the map after appending
|
||||
debugInfo["cookies"] = cookies
|
||||
}
|
||||
|
||||
// Log with pretty formatting
|
||||
logger.Info("DEBUG REQUEST",
|
||||
"details", debugInfo,
|
||||
)
|
||||
|
||||
return next(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getSlogCustomEchoMiddleware(logger *slog.Logger) echo.MiddlewareFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
@@ -118,6 +178,9 @@ func New(ctx context.Context, cfg Config) (*Server, error) {
|
||||
e.Use(middleware.Recover())
|
||||
e.Use(middleware.CORS())
|
||||
|
||||
// Add debug middleware early to catch all requests
|
||||
e.Use(getDebugMiddleware(cfg.GetLogger()))
|
||||
|
||||
cfg.SetRouter(e)
|
||||
opnapi, err := cfg.RegisterHandlers()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user