middleware

package
v1.39.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
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

func (*CorsMiddleware) Handler added in v1.3.0

func (cm *CorsMiddleware) Handler(next http.Handler) http.Handler

Handler implements the middlewares.Handlerer interface: it returns a http.Handler to be mounted as middleware. The handler calls cors.Cors.Handler

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

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

type DatabaseMiddleware struct {
	Database *gorm.DB
}

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.

func (DatabaseMiddleware) Handler

func (dm DatabaseMiddleware) Handler(next http.Handler) http.Handler

Handler implements the middlewares.Handlerer interface: it returns a http.Handler to be mounted as middleware. The handler injects the database connection pool to the request context.

type Handlerer

type Handlerer interface {
	Handler(next http.Handler) http.Handler
}

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.

func (MetricsMiddleware) Handler

func (sm MetricsMiddleware) Handler(next http.Handler) http.Handler

Handler implements the middlewares.Handlerer interface: it returns a http.Handler to be mounted as middleware. The handler injects the Metrics client to the request context.

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.

func (RequestIDMiddleware) Handler

func (rm RequestIDMiddleware) Handler(next http.Handler) http.Handler

Handler implements the middlewares.Handlerer interface. Returns an http.Handler to inject the RequestID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL