Documentation ¶
Index ¶
- Constants
- Variables
- func DecrementModifier(value any) (any, error)
- func GetSortDirectionName(sortDirection client.SortDirection) string
- func IpCaster(value any) (any, error)
- func ValueOrZeroModifier(value any) (any, error)
- type Caster
- type DurationMetric
- type Getter
- type Modifier
- type Option
- func AddGetter(getter Getter) Option
- func WithChiURLParam(name string) Option
- func WithCookie(name string) Option
- func WithDefault(value any) Option
- func WithHeader(name string) Option
- func WithModifier(modifier Modifier) Option
- func WithName(name string) Option
- func WithUri(name string) Option
- func WithValidator(validator Validator) Option
- type Page
- type Param
- func NewIp(logger logger.Logger) *Param
- func NewPagination(logger logger.Logger, allowedColumns ...string) []*Param
- func NewPaginationLimit(logger logger.Logger) *Param
- func NewPaginationPage(logger logger.Logger) *Param
- func NewPaginationSortColumn(logger logger.Logger, allowedColumns ...string) *Param
- func NewPaginationSortDirection(logger logger.Logger) *Param
- func NewParam(logger logger.Logger, caster Caster, options ...Option) *Param
- func NewParamBool(logger logger.Logger, options ...Option) *Param
- func NewParamDuration(logger logger.Logger, options ...Option) *Param
- func NewParamFloat32(logger logger.Logger, options ...Option) *Param
- func NewParamFloat64(logger logger.Logger, options ...Option) *Param
- func NewParamInt(logger logger.Logger, options ...Option) *Param
- func NewParamInt16(logger logger.Logger, options ...Option) *Param
- func NewParamInt32(logger logger.Logger, options ...Option) *Param
- func NewParamInt64(logger logger.Logger, options ...Option) *Param
- func NewParamInt8(logger logger.Logger, options ...Option) *Param
- func NewParamString(logger logger.Logger, options ...Option) *Param
- func NewParamTime(logger logger.Logger, options ...Option) *Param
- func NewParamUUID(logger logger.Logger, options ...Option) *Param
- func NewParamUint(logger logger.Logger, options ...Option) *Param
- func NewParamUint16(logger logger.Logger, options ...Option) *Param
- func NewParamUint32(logger logger.Logger, options ...Option) *Param
- func NewParamUint64(logger logger.Logger, options ...Option) *Param
- func NewParamUint8(logger logger.Logger, options ...Option) *Param
- type RequestLogger
- type ResponseLogger
- type Sort
- type TotalRequestCount
- type Validator
Constants ¶
View Source
const ( PageFieldName = "page" LimitFieldName = "limit" SortColumnFieldName = "colSort" SortDirectionFieldName = "direction" CountHeaderName = "X-Pagination-Count" PageHeaderName = "X-Pagination-Page" LimitHeaderName = "X-Pagination-Limit" SortColumnHeaderName = "X-Pagination-Sort-Column" SortDirectionHeaderName = "X-Pagination-Sort-Direction" SortDirectionAsc = "asc" SortDirectionDesc = "desc" SortColumnDefault = "id" LimitDefault = uint8(20) PageDefault = uint32(1) IpFieldName = "ip" HeaderRealIp = "X-REAL-IP" HeaderForwardedFor = "X-FORWARDED-FOR" )
Variables ¶
View Source
var ( MetricTotalRequestCountComponent = &app.Component{ Dependencies: app.Components{ logger.Component, router.Component, }, Constructor: func(container container.Container) error { return container.Provide(NewTotalRequestCount) }, Run: func(c container.Container) error { metric, err := container.Get[*TotalRequestCount](c) if err != nil { return err } router, err := container.Get[router.Router](c) if err != nil { return err } informer, err := container.Get[logger.Informer](c) if err != nil { return err } informer.Info("http.server.middleware: added a metric for the total number of requests") router.Use(metric) return nil }, } MetricDurationComponent = &app.Component{ Dependencies: app.Components{ logger.Component, router.Component, }, Constructor: func(container container.Container) error { return container.Provide(NewDurationMetric) }, Run: func(c container.Container) error { metric, err := container.Get[*DurationMetric](c) if err != nil { return err } router, err := container.Get[router.Router](c) if err != nil { return err } informer, err := container.Get[logger.Informer](c) if err != nil { return err } informer.Info("http.server.middleware: added metric of query execution time counter") router.Use(metric) return nil }, } ResponseLoggerComponent = &app.Component{ Dependencies: app.Components{ logger.Component, router.Component, }, Constructor: func(container container.Container) error { return container.Provide(NewResponseLogger) }, Run: func(c container.Container) error { loggerMiddleware, err := container.Get[*ResponseLogger](c) if err != nil { return err } router, err := container.Get[router.Router](c) if err != nil { return err } informer, err := container.Get[logger.Informer](c) if err != nil { return err } informer.Info("http.server.middleware: added response logger") router.Use(loggerMiddleware) return nil }, } RequestLoggerComponent = &app.Component{ Dependencies: app.Components{ logger.Component, router.Component, }, Constructor: func(container container.Container) error { return container.Provide(NewRequestLogger) }, Run: func(c container.Container) error { loggerMiddleware, err := container.Get[*RequestLogger](c) if err != nil { return err } router, err := container.Get[router.Router](c) if err != nil { return err } informer, err := container.Get[logger.Informer](c) if err != nil { return err } informer.Info("http.server.middleware: added request logger") router.Use(loggerMiddleware) return nil }, } )
Functions ¶
func DecrementModifier ¶
func GetSortDirectionName ¶ added in v1.1.0
func GetSortDirectionName(sortDirection client.SortDirection) string
func ValueOrZeroModifier ¶
Types ¶
type DurationMetric ¶
type DurationMetric struct {
// contains filtered or unexported fields
}
func NewDurationMetric ¶
func NewDurationMetric(appConfig *app.Config) *DurationMetric
func (*DurationMetric) Middleware ¶
func (middleware *DurationMetric) Middleware(next http.Handler) http.Handler
type Option ¶
func WithChiURLParam ¶
func WithCookie ¶
func WithDefault ¶
func WithHeader ¶
func WithModifier ¶
func WithValidator ¶
type Param ¶
type Param struct {
// contains filtered or unexported fields
}
func NewPaginationLimit ¶
func NewPaginationPage ¶
func NewPaginationSortColumn ¶
type RequestLogger ¶
type RequestLogger struct {
// contains filtered or unexported fields
}
func NewRequestLogger ¶
func NewRequestLogger(logger logger.Logger) *RequestLogger
func (*RequestLogger) Middleware ¶
func (r *RequestLogger) Middleware(next http.Handler) http.Handler
type ResponseLogger ¶
type ResponseLogger struct {
// contains filtered or unexported fields
}
func NewResponseLogger ¶
func NewResponseLogger(logger logger.Logger) *ResponseLogger
func (*ResponseLogger) Middleware ¶
func (r *ResponseLogger) Middleware(next http.Handler) http.Handler
type TotalRequestCount ¶
type TotalRequestCount struct {
// contains filtered or unexported fields
}
func NewTotalRequestCount ¶
func NewTotalRequestCount(appConfig *app.Config) *TotalRequestCount
func (*TotalRequestCount) Middleware ¶
func (middleware *TotalRequestCount) Middleware(next http.Handler) http.Handler
Click to show internal directories.
Click to hide internal directories.