Documentation
¶
Index ¶
- Variables
- func AddLoggerOptions(app Flagger)
- func ContentEncoding(next http.Handler) http.Handler
- func DefaultChain(next http.Handler) http.Handler
- func Defaults(app Middlewarer)
- func GetBufferedBody(ctx context.Context) []byte
- func GetLogger(ctx context.Context) *zap.SugaredLogger
- func Logger(next http.Handler) http.Handler
- func NewDefaultLogger() (*zap.Logger, error)
- func OpenTracing(next http.Handler) http.Handler
- func PreferMinimal(next http.Handler) http.Handler
- func Recovery(onPanic PanicFunc) func(http.Handler) http.Handler
- func SetLogger(r *http.Request, logger *zap.SugaredLogger) *http.Request
- func SetLoggerInContext(ctx huma.Context, logger *zap.SugaredLogger)
- type Flagger
- type Middlewarer
- type PanicFunc
Constants ¶
This section is empty.
Variables ¶
var LogLevel *zap.AtomicLevel
LogLevel sets the current Zap root logger's level when using the logging middleware. This can be changed dynamically at runtime.
var LogTracePrefix = "dd."
LogTracePrefix is used to prefix OpenTracing trace and span ID key names in emitted log message tag names. Use this to integrate with DataDog and other tracing service providers.
var MaxLogBodyBytes int64 = 10 * 1024
MaxLogBodyBytes logs at most this many bytes of any request body during a panic when using the recovery middleware. Defaults to 10KiB. Changing this value changes the amount of potential memory used for *each* incoming request, so change it carefully and complement the change with load testing because larger values can have a detrimental effect on the server.
var NewLogger func() (*zap.Logger, error) = NewDefaultLogger
NewLogger is a function that returns a new logger instance to use with the logger middleware.
Functions ¶
func AddLoggerOptions ¶
func AddLoggerOptions(app Flagger)
AddLoggerOptions adds command line options for enabling debug logging.
func ContentEncoding ¶
ContentEncoding uses content negotiation with the client to pick an appropriate encoding (compression) method and transparently encodes the response. Supports GZip and Brotli.
func DefaultChain ¶
DefaultChain sets up the default middlewares conveniently chained together into a single easy-to-add handler.
func Defaults ¶
func Defaults(app Middlewarer)
Defaults sets up the default middleware. This convenience function adds the `DefaultChain` to the router and adds the `--debug` option for logging to the CLI if app is a CLI.
func GetBufferedBody ¶
GetBufferedBody returns the buffered body from a request when using the recovery middleware, up to MaxLogBodyBytes.
func GetLogger ¶
func GetLogger(ctx context.Context) *zap.SugaredLogger
GetLogger returns the contextual logger for the current request. If no logger is present, it returns a no-op logger so no nil check is required.
func Logger ¶
Logger creates a new middleware to set a tagged `*zap.SugarLogger` in the request context. It debug logs request info. If the current terminal is a TTY, it will try to use colored output automatically.
func NewDefaultLogger ¶
NewDefaultLogger returns a new low-level `*zap.Logger` instance. If the current terminal is a TTY, it will try ot use colored output automatically.
func OpenTracing ¶
OpenTracing provides a middleware for cross-service tracing support.
func PreferMinimal ¶
PreferMinimal will remove the response body and return 204 No Content for any 2xx response where the request had the Prefer: return=minimal set on the request.
func SetLoggerInContext ¶
func SetLoggerInContext(ctx huma.Context, logger *zap.SugaredLogger)
SetLoggerInContext allows you to override the logger in the current request context. This is useful for modifying the logger in input resolvers.
Types ¶
type Flagger ¶
type Flagger interface { Flag(name string, short string, description string, defaultValue interface{}) PreStart(f func()) }
Flagger lets you create command line flags and functions that use them.
type Middlewarer ¶
Middlewarer lets you add middlewares