Documentation ¶
Index ¶
- Constants
- Variables
- func CustomLogger(next http.Handler) http.Handler
- func CustomRequestLogger(f chimiddleware.LogFormatter) func(next http.Handler) http.Handler
- func CustomZapLogger(next http.Handler) http.Handler
- func CustomZapRequestLogger(f chimiddleware.LogFormatter) func(next http.Handler) http.Handler
- func NewChiRouterSimple(config ConfigSimple) *chi.Mux
- func NewMetricMiddleware(namespace string, prometheusLabels stdprometheus.Labels, name string, ...) func(next http.Handler) http.Handler
- func UnverifiedAuthenticator(next http.Handler) http.Handler
- type ConfigSimple
- type CustomLogFormatter
- type CustomZapLogFormatter
- type MetricMiddleware
Constants ¶
const ( //ContextKeyUser is used as key to add the user data in the request context ContextKeyUser keyContext = iota //ContextKeyLoggerR is used as key to add the value of the http.Request at the CustomLogger middlewere execution ContextKeyLoggerR //UserLogin is used as key to add the userloging into the request context UserLogin )
Variables ¶
var ( // RequestLogger is called by the Logger middleware handler to log each request. // Its made a package-level variable so that it can be reconfigured for custom // logging configurations. RequestLogger = CustomRequestLogger(&CustomLogFormatter{Logger: log.New(os.Stdout, "", log.LstdFlags), NoColor: false}) )
var ( // ZapRequestLogger is called by the Logger middleware handler to log each request. // Its made a package-level variable so that it can be reconfigured for custom // logging configurations. ZapRequestLogger = CustomZapRequestLogger(&CustomZapLogFormatter{Logger: log.New(os.Stdout, "", log.LstdFlags), NoColor: false}) )
Functions ¶
func CustomLogger ¶
CustomLogger is a middleware that logs the start and end of each request, along with some useful data about what was requested, what the response status was, and how long it took to return. When standard output is a TTY, Logger will print in color, otherwise it will print in black and white. Logger prints a request ID if one is provided.
Alternatively, look at https://github.com/pressly/lg and the `lg.RequestLogger` middleware pkg.
func CustomRequestLogger ¶
func CustomRequestLogger(f chimiddleware.LogFormatter) func(next http.Handler) http.Handler
CustomRequestLogger returns a logger handler using a custom LogFormatter.
func CustomZapLogger ¶
CustomZapLogger is a middleware that logs the start and end of each request, along with some useful data about what was requested, what the response status was, and how long it took to return. When standard output is a TTY, Logger will print in color, otherwise it will print in black and white. Logger prints a request ID if one is provided.
Alternatively, look at https://github.com/pressly/lg and the `lg.RequestLogger` middleware pkg.
func CustomZapRequestLogger ¶
func CustomZapRequestLogger(f chimiddleware.LogFormatter) func(next http.Handler) http.Handler
CustomZapRequestLogger returns a logger handler using a custom LogFormatter.
func NewChiRouterSimple ¶ added in v4.1.11
func NewChiRouterSimple(config ConfigSimple) *chi.Mux
NewChiRouter initialize a chi.Mux router with all required default middleware (logger, security, recovery, etc.)
func NewMetricMiddleware ¶ added in v4.1.11
func NewMetricMiddleware(namespace string, prometheusLabels stdprometheus.Labels, name string, buckets ...float64) func(next http.Handler) http.Handler
NewMetricMiddleware returns a new prometheus MetricMiddleware handler.
func UnverifiedAuthenticator ¶ added in v4.1.11
UnverifiedAuthenticator doc WARNING: Don't use this method unless you know what you're doing This method parses the token but doesn't validate the signature. It's only ever useful in cases where you know the signature is valid (because it has been checked previously in the stack) and you want to extract values from it.
Types ¶
type ConfigSimple ¶ added in v4.1.11
type ConfigSimple struct { Production bool Security bool CORS bool GatewayMode bool VerboseError bool AuthenticationMode string LogLevel zap.AtomicLevel MetricsNamespace string MetricsPrometheusLabels stdprometheus.Labels MetricsServiceName string PublicRoutes map[string]http.Handler ProtectedRoutes map[string]http.Handler }
ConfigSimple wraps common configuration parameters
func (*ConfigSimple) Check ¶ added in v4.1.11
func (config *ConfigSimple) Check()
Check clean up the configuration and logs comments if required
type CustomLogFormatter ¶
type CustomLogFormatter struct { Logger chimiddleware.LoggerInterface NoColor bool }
CustomLogFormatter is a simple logger that implements a LogFormatter.
func (*CustomLogFormatter) NewLogEntry ¶
func (l *CustomLogFormatter) NewLogEntry(r *http.Request) chimiddleware.LogEntry
NewLogEntry creates a new LogEntry for the request.
type CustomZapLogFormatter ¶
type CustomZapLogFormatter struct { Logger chimiddleware.LoggerInterface NoColor bool }
CustomZapLogFormatter is a simple logger that implements a LogFormatter.
func (*CustomZapLogFormatter) NewLogEntry ¶
func (l *CustomZapLogFormatter) NewLogEntry(r *http.Request) chimiddleware.LogEntry
NewLogEntry creates a new LogEntry for the request.
type MetricMiddleware ¶ added in v4.1.11
type MetricMiddleware struct {
// contains filtered or unexported fields
}
MetricMiddleware is a handler that exposes prometheus metrics for the number of requests, the latency and the response size, partitioned by status code, method and HTTP path.