Documentation ¶
Index ¶
Constants ¶
const ( // ForwardedForHeader is the 'X-Forwarded-For' (XFF) HTTP header // field. It is a common method for identifying the originating // IP address of a client connecting to a web server through an // HTTP proxy or load balancer. ForwardedForHeader = "X-Forwarded-For" )
const ( // RequestIDHeader is the header key for carrying the RequestID. RequestIDHeader string = "X-Request-Id" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CorsMiddleware ¶ added in v1.3.0
type CorsMiddleware struct {
// contains filtered or unexported fields
}
CorsMiddleware wraps *cors.Cors that will act as a middleware implementation
func NewCorsMiddleware ¶ added in v1.3.0
func NewCorsMiddleware(setting server.CorsSetting) *CorsMiddleware
NewCorsMiddleware creates cors.Cors middleware and attaches it to the CorsMiddleware wrapper
type DatabaseLoggingMiddleware ¶
type DatabaseLoggingMiddleware struct{}
DatabaseLoggingMiddleware wraps an instantiated sdk.Logger that will be injected in the request context.
func NewDatabaseLoggingMiddleware ¶
func NewDatabaseLoggingMiddleware() DatabaseLoggingMiddleware
NewLoggingMiddleware is a wrapper of an SDK Logger. It can be used to build a LoggingMiddleware.
func (DatabaseLoggingMiddleware) Handler ¶
func (dlm DatabaseLoggingMiddleware) Handler(next http.Handler) http.Handler
Handler implements go-sdk's middleware.Handlerer interface: it returns a http.Handler to be mounted as middleware. This handler extracts the logger from the request context, attaches it to gorm's database connection pool and logs the database queries with their meta-information using the logger.
type DatabaseMiddleware ¶
DatabaseMiddleware wraps an instantiated *gorm.DB that will be injected in the request context.
func NewDatabaseMiddleware ¶
func NewDatabaseMiddleware(d *gorm.DB) DatabaseMiddleware
NewDatabaseMiddleware is a constructor used to build a DatabaseMiddleware.
type Handlerer ¶
A Handlerer provides a http.Handler that responds to an HTTP request. The returned Handler can be mounted as Middleware.
type LoggingMiddleware ¶
type LoggingMiddleware struct {
// contains filtered or unexported fields
}
LoggingMiddleware wraps an instantiated sdk.Logger that will be injected in the request context.
func NewLoggingMiddleware ¶
func NewLoggingMiddleware(l sdklogger.Logger) LoggingMiddleware
NewLoggingMiddleware is a wrapper of an SDK Logger. It can be used to build a LoggingMiddleware.
func (LoggingMiddleware) Handler ¶
func (lm LoggingMiddleware) Handler(next http.Handler) http.Handler
Handler implements the middlewares.Handlerer interface: it returns a http.Handler to be mounted as middleware. This handler logs every HTTP requests that it receives with its internal logger extracting various details from the request itself and calculates the total elapsed time per request in milliseconds.
type MetricsMiddleware ¶
type MetricsMiddleware struct {
Metrics sdkmetrics.Metrics
}
MetricsMiddleware wraps an instantiated Metrics client that will be injected in the request context.
func NewMetricsMiddleware ¶
func NewMetricsMiddleware(metrics sdkmetrics.Metrics) MetricsMiddleware
NewMetricsMiddleware is a constructor used to build a MetricsMiddleware.
type RecoveryMiddleware ¶ added in v1.34.0
type RecoveryMiddleware struct{}
RecoveryMiddleware is a middleware that recovers from panics and logs them.
func NewRecoveryMiddleware ¶ added in v1.34.0
func NewRecoveryMiddleware() RecoveryMiddleware
NewRecoveryMiddleware is a constructor used to build a RecoveryMiddleware. IMPORTANT: This middleware should be the last one in the middleware chain.
func (RecoveryMiddleware) Handler ¶ added in v1.34.0
func (rm RecoveryMiddleware) Handler(next http.Handler) http.Handler
Handler implements the middlewares.Handlerer interface: it returns a http.Handler to be mounted as middleware. The Handler recovers from a panic, sends a sentry event, sends fatal error log and halts the service.
type RequestIDMiddleware ¶
type RequestIDMiddleware struct{}
RequestIDMiddleware propagates or sets a request ID to the incoming request setting the value both in the HTTP header and in the request context.
func NewRequestIDMiddleware ¶
func NewRequestIDMiddleware() RequestIDMiddleware
NewRequestIDMiddleware creates a new RequestIDMiddleware.