- Replace manual IP logging with the `withRequestLogAttrs` helper in authentication handlers. - Add user activity logging for API documentation and login page views. - Clean up log calls to use variadic expansion of request attributes.
30 lines
657 B
Go
30 lines
657 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"warpbox.dev/backend/libs/middleware"
|
|
)
|
|
|
|
func requestLogAttrs(r *http.Request) []any {
|
|
attrs := []any{
|
|
"ip", uploadClientIP(r),
|
|
"method", r.Method,
|
|
"path", r.URL.Path,
|
|
}
|
|
if requestID := middleware.RequestIDFromContext(r.Context()); requestID != "" {
|
|
attrs = append(attrs, "request_id", requestID)
|
|
}
|
|
if userAgent := r.UserAgent(); userAgent != "" {
|
|
attrs = append(attrs, "user_agent", userAgent)
|
|
}
|
|
return attrs
|
|
}
|
|
|
|
func withRequestLogAttrs(r *http.Request, attrs ...any) []any {
|
|
out := make([]any, 0, len(attrs)+8)
|
|
out = append(out, attrs...)
|
|
out = append(out, requestLogAttrs(r)...)
|
|
return out
|
|
}
|