Documentation ¶
Index ¶
- func ChiRouteName(r *http.Request) string
- func MethodAndPathCleanID(r *http.Request) string
- func PathWithCleanID(r *http.Request) string
- func WithCORS(allowedOrigins, allowedMethods, allowedHeaders []string, allowCredentials bool) server.Option
- func WithCORSWideOpen() server.Option
- func WithMetrics(app string, opNameFunc func(r *http.Request) string) server.Option
- func WithRecovery(writer io.Writer, printStack bool) server.Option
- func WithTracing(app string, tags map[string]string, opNameFunc func(r *http.Request) string) server.Option
- type LoggingOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChiRouteName ¶
ChiRouteName replace route parameters from the Chi route mux with "*"
func MethodAndPathCleanID ¶
MethodAndPathCleanID replace string values that look like ids (uuids and int) with "*"
func PathWithCleanID ¶
PathWithCleanID replace string values that look like ids (uuids and int) with "*"
func WithCORS ¶
func WithCORS(allowedOrigins, allowedMethods, allowedHeaders []string, allowCredentials bool) server.Option
WithCORS configures CORS on the webserver
func WithCORSWideOpen ¶
WithCORSWideOpen allows requests from all origins with all methods and all headers/cookies/credentials allowed.
func WithMetrics ¶
WithMetrics configures metrics collection
func WithRecovery ¶
WithRecovery configures panic recovery for that server
Types ¶
type LoggingOption ¶ added in v4.12.0
type LoggingOption struct { // Ignore determines if the log should be skipped for the given request. // // When nil, the default logic is used, which ignores requests in which the // User-Agent contains: "healthcheck" or "kube-probe". Ignore func(r *http.Request) bool // Fields extracts log fields from the given trequest to include in the log entry. // // When nil, the default logic is used, which includes the request method and path. Fields func(r *http.Request) logrus.Fields // contains filtered or unexported fields }
func WithLogging ¶
func WithLogging(app string) *LoggingOption
WithLogging configures a logrus middleware for that server.
You can control the log fields or if the log should be skipped by setting the Fields and the Ignore function respectively.
log := middlewares.WithLogging(config.ApplicationName) log.Fields = func(r *http.Request) logrus.Fields { // custom logic here } log.Ignore = func(r *http.Request) bool { // custom logic here }
When `tracing.SpanHook` is enabled and the tracing middleware is enabled before the logging middleware, the traceId and spanId are attaced the the logs.
During application configuration use
logrus.AddHook(&tracing.SpanHook{})
During router configuration
recover := middlewares.WithRecovery(os.Stderr, cfg.Debug) trace := middlewares.WithTracing(config.ApplicationName, nil, middlewares.ChiRouteName) log := middlewares.WithLogging(config.ApplicationName) metrics := middlewares.WithMetrics(config.ApplicationName, nil) api.Use( recover.WrapHandler, trace.WrapHandler, log.WrapHandler, metrics.WrapHandler, )
func (*LoggingOption) WrapHandler ¶ added in v4.12.0
func (opt *LoggingOption) WrapHandler(handler http.Handler) http.Handler