sync from project

This commit is contained in:
2025-06-18 10:12:19 +08:00
parent 61ffeeb3b8
commit fb579e8689
20 changed files with 1332 additions and 103 deletions

View File

@ -75,6 +75,10 @@ func (log Log) WrapHandler(next http.Handler) http.Handler {
})
}
// Logger retrieves the slog.Logger from the request context.
// If the logger is not found in the context (e.g., the httplog middleware is not used),
// it creates and returns a new logger with basic request information.
// Using the httplog middleware is recommended to ensure the configured logger is available.
func Logger(r *http.Request) *slog.Logger {
if logger, ok := r.Context().Value(loggerKey).(*slog.Logger); ok {
return logger.With("time", time.Now())