middleware

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOperationNotFound indicates the operation was not found in context.
	ErrOperationNotFound = errors.New("operation not found in request context")

	// ErrPrincipalNotFound indicates the principal was not found in context.
	ErrPrincipalNotFound = errors.New("principal not found in request context")

	// ErrRequestNotFound indicates the request was not found in context.
	ErrRequestNotFound = errors.New("request not found in request context")

	// ErrAuthStrategyNotFound indicates the auth strategy was not registered.
	ErrAuthStrategyNotFound = errors.New("authentication strategy not found")

	// ErrPermissionCheckerNotProvided indicates no permission checker was configured.
	ErrPermissionCheckerNotProvided = errors.New("permission checker not provided")

	// ErrDataPermissionResolverNotProvided indicates no data permission resolver was configured.
	ErrDataPermissionResolverNotProvided = errors.New("data permission resolver not provided")

	// ErrPermissionDenied indicates the principal does not have the required permission.
	ErrPermissionDenied = errors.New("permission denied")

	// ErrPermissionCheckFailed indicates an error occurred during permission check.
	ErrPermissionCheckFailed = errors.New("permission check failed")

	// ErrDataScopeResolutionFailed indicates an error occurred during data scope resolution.
	ErrDataScopeResolutionFailed = errors.New("data scope resolution failed")

	// ErrAuditEventBuildFailed indicates an error occurred while building audit event.
	ErrAuditEventBuildFailed = errors.New("failed to build audit event")

	// ErrResponseDecodeFailed indicates an error occurred while decoding response body.
	ErrResponseDecodeFailed = errors.New("failed to decode response body")
)
View Source
var Module = fx.Module(
	"vef:api:middleware",
	fx.Provide(
		fx.Private,
		fx.Annotate(
			NewAudit,
			fx.ResultTags(`group:"vef:api:middlewares"`),
		),
		fx.Annotate(
			NewAuth,
			fx.ResultTags(`group:"vef:api:middlewares"`),
		),
		fx.Annotate(
			NewContextual,
			fx.ResultTags(`group:"vef:api:middlewares"`),
		),
		fx.Annotate(
			NewDataPermission,
			fx.ResultTags(`group:"vef:api:middlewares"`),
		),
		fx.Annotate(
			NewRateLimit,
			fx.ResultTags(`group:"vef:api:middlewares"`),
		),
	),
	fx.Provide(
		fx.Annotate(
			NewChain,
			fx.ParamTags(`group:"vef:api:middlewares"`),
		),
	),
)

Functions

func NewAudit

func NewAudit(publisher event.Publisher) api.Middleware

NewAudit creates a new audit middleware.

func NewAuth

NewAuth creates a new authentication middleware.

func NewContextual

func NewContextual(db orm.DB) api.Middleware

NewContextual creates a new context middleware.

func NewDataPermission

func NewDataPermission(resolver security.DataPermissionResolver) api.Middleware

NewDataPermission creates a new data permission middleware.

func NewRateLimit

func NewRateLimit() api.Middleware

NewRateLimit creates a new rate limit middleware with shared state.

Types

type Audit

type Audit struct {
	// contains filtered or unexported fields
}

Audit handles audit logging.

func (*Audit) Name

func (*Audit) Name() string

Name returns the middleware name.

func (*Audit) Order

func (*Audit) Order() int

Order returns the middleware order.

func (*Audit) Process

func (m *Audit) Process(ctx fiber.Ctx) error

Process handles the audit logging.

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

func (*Auth) Name

func (*Auth) Name() string

Name returns the middleware name.

func (*Auth) Order

func (*Auth) Order() int

Order returns the middleware order. Authentication runs first in the middleware chain.

func (*Auth) Process

func (m *Auth) Process(ctx fiber.Ctx) error

Process handles the authentication.

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

Chain manages the middleware chain for API requests.

func NewChain

func NewChain(middlewares ...api.Middleware) *Chain

NewChain creates a new middleware chain with the given middlewares. Middlewares are sorted by their Order() value (ascending).

func (*Chain) Handlers

func (c *Chain) Handlers() []any

Handlers converts the chain's middlewares into a slice of fiber.Handler. The returned handlers maintain the execution order (sorted by Order ascending), ensuring that middlewares with lower Order() values execute first.

type Contextual

type Contextual struct {
	// contains filtered or unexported fields
}

Contextual injects DB and Logger into the request context. It sets up a contextual database with the operator ID and a scoped logger with request identification information.

func (*Contextual) Name

func (*Contextual) Name() string

Name returns the middleware name.

func (*Contextual) Order

func (*Contextual) Order() int

Order returns the middleware order. Runs after authentication (-100) but before authorization (-90).

func (*Contextual) Process

func (m *Contextual) Process(ctx fiber.Ctx) error

Process sets up the request context with DB and Logger.

type DataPermissionMiddleware

type DataPermissionMiddleware struct {
	// contains filtered or unexported fields
}

DataPermissionMiddleware handles data permission resolution. It resolves data scope for the current principal and permission token, then injects a RequestScopedDataPermApplier into the context.

func (*DataPermissionMiddleware) Name

Name returns the middleware name.

func (*DataPermissionMiddleware) Order

func (*DataPermissionMiddleware) Order() int

Order returns the middleware order. Runs after authentication (-100) but before rate limiting (-80).

func (*DataPermissionMiddleware) Process

func (m *DataPermissionMiddleware) Process(ctx fiber.Ctx) error

Process handles the data permission resolution.

type RateLimit

type RateLimit struct {
	// contains filtered or unexported fields
}

RateLimit handles rate limiting based on operation config. It uses a shared in-memory store to maintain state across requests.

func (*RateLimit) Name

func (*RateLimit) Name() string

Name returns the middleware name.

func (*RateLimit) Order

func (*RateLimit) Order() int

Order returns the middleware order.

func (*RateLimit) Process

func (m *RateLimit) Process(ctx fiber.Ctx) error

Process handles the rate limiting.

Jump to

Keyboard shortcuts

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