Documentation
¶
Overview ¶
Package middleware implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Package middleware contains generated code by adptool.
Package middleware implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Index ¶
- Constants
- func GetSigningMethod(alg string) jwt.SigningMethod
- func KChain(m ...middleware.Middleware) middleware.Middleware
- func NewClaimsFactory(cfg *jwtv1.JWT, opts *Options) func() jwt.Claims
- func RegisterFactory(name Name, factory Factory)
- type Builder
- type Carrier
- type Factory
- type KHandler
- type KMiddleware
- func BuildClients(cfg *middlewarev1.Middlewares, opts ...Option) []KMiddleware
- func BuildServers(cfg *middlewarev1.Middlewares, opts ...Option) []KMiddleware
- func JwtClient(cfg *jwtv1.JWT, opts *Options) (KMiddleware, bool)
- func JwtServer(cfg *jwtv1.JWT, opts *Options) (KMiddleware, bool)
- func NewClient(cfg *middlewarev1.Middleware, opts ...Option) (KMiddleware, bool)
- func NewServer(cfg *middlewarev1.Middleware, opts ...Option) (KMiddleware, bool)
- func Noop() KMiddleware
- func SelectorClient(cfg *selectorv1.Selector, matchFunc selector.MatchFunc, ...) KMiddleware
- func SelectorServer(cfg *selectorv1.Selector, matchFunc selector.MatchFunc, ...) KMiddleware
- func Validate(ms []KMiddleware, validator *validatorv1.Validator) []KMiddleware
- func ValidateServer(ms []KMiddleware, validator *validatorv1.Validator) []KMiddleware
- type Name
- type Option
- func WithCarrier(carrier *Carrier) Option
- func WithClaimsFactory(factory func() jwt.Claims) Option
- func WithClientCarrier(clientMiddlewares map[string]KMiddleware) Option
- func WithMatchFunc(matchFunc selector.MatchFunc) Option
- func WithServerCarrier(serverMiddlewares map[string]KMiddleware) Option
- func WithSigningMethod(method jwt.SigningMethod) Option
- func WithSubjectFactory(factory func() string) Option
- type Options
Constants ¶
const Type = "middleware"
Variables ¶
This section is empty.
Functions ¶
func GetSigningMethod ¶ added in v0.2.13
func GetSigningMethod(alg string) jwt.SigningMethod
GetSigningMethod returns the jwt.SigningMethod based on the provided string. Exported for testing purposes.
func KChain ¶ added in v0.2.6
func KChain(m ...middleware.Middleware) middleware.Middleware
func NewClaimsFactory ¶ added in v0.2.13
NewClaimsFactory is a higher-order function that takes JWT configuration and returns a `func() jwt.Claims`. This returned function, when called, generates a new set of claims based on the provided configuration. It automatically handles issuer, lifetime, and generates a random UUID for the subject. The implementation is optimized to avoid recreating static configuration on each call. Exported for testing purposes.
func RegisterFactory ¶ added in v0.2.13
RegisterFactory registers a middleware factory with the given name.
Types ¶
type Builder ¶ added in v0.2.0
Builder is a builder for creating middleware chains.
func NewBuilder ¶ added in v0.2.0
func NewBuilder() *Builder
NewBuilder creates a new middleware builder.
func (*Builder) BuildClientMiddlewares ¶ added in v0.2.7
func (b *Builder) BuildClientMiddlewares(cfg *middlewarev1.Middlewares, opts ...Option) []KMiddleware
BuildClientMiddlewares builds the client middleware chain
func (*Builder) BuildServerMiddlewares ¶ added in v0.2.7
func (b *Builder) BuildServerMiddlewares(cfg *middlewarev1.Middlewares, opts ...Option) []KMiddleware
BuildServerMiddlewares builds the server middleware chain (similar to BuildClient)
type Carrier ¶ added in v0.2.6
type Carrier struct {
Clients map[string]KMiddleware
Servers map[string]KMiddleware
}
Carrier is a struct that holds the middlewares for client and server.
type Factory ¶ added in v0.2.0
type Factory interface {
// NewMiddlewareClient builds a client-side middleware.
NewMiddlewareClient(*middlewarev1.Middleware, ...Option) (KMiddleware, bool)
// NewMiddlewareServer builds a server-side middleware.
NewMiddlewareServer(*middlewarev1.Middleware, ...Option) (KMiddleware, bool)
}
Factory is an interface that defines a method for creating a new buildImpl. It receives the middleware-specific Protobuf configuration and the generic Option slice. Each factory is responsible for parsing the options it cares about (e.g., by using log.FromOptions).
type KHandler ¶ added in v0.1.18
type KHandler = middleware.Handler
type KMiddleware ¶ added in v0.1.18
type KMiddleware = middleware.Middleware
func BuildClients ¶ added in v0.2.13
func BuildClients(cfg *middlewarev1.Middlewares, opts ...Option) []KMiddleware
BuildClients creates a new client middleware chain using the default builder. This is the public API for building client-side middlewares.
func BuildServers ¶ added in v0.2.13
func BuildServers(cfg *middlewarev1.Middlewares, opts ...Option) []KMiddleware
BuildServers creates a new server middleware chain using the default builder. This is the public API for building server-side middlewares.
func JwtClient ¶ added in v0.1.15
func JwtClient(cfg *jwtv1.JWT, opts *Options) (KMiddleware, bool)
JwtClient creates a Kratos client middleware for JWT token generation and injection. This middleware dynamically creates a new `authjwt.Client` instance for each request, ensuring that the JWT is generated based on the claims present in the request's context.
func JwtServer ¶ added in v0.1.15
func JwtServer(cfg *jwtv1.JWT, opts *Options) (KMiddleware, bool)
JwtServer creates a Kratos server middleware for JWT authentication. It uses the provided JWT configuration to validate incoming tokens.
func NewClient ¶
func NewClient(cfg *middlewarev1.Middleware, opts ...Option) (KMiddleware, bool)
NewClient creates a single client-side middleware instance. This is the public API for creating individual client-side middlewares.
func NewServer ¶
func NewServer(cfg *middlewarev1.Middleware, opts ...Option) (KMiddleware, bool)
NewServer creates a single server-side middleware instance. This is the public API for creating individual server-side middlewares.
func SelectorClient ¶ added in v0.1.15
func SelectorClient(cfg *selectorv1.Selector, matchFunc selector.MatchFunc, middlewares ...KMiddleware) KMiddleware
SelectorClient creates a selector middleware for client-side. This helper function is still available for direct use if needed to wrap specific middlewares.
func SelectorServer ¶ added in v0.1.15
func SelectorServer(cfg *selectorv1.Selector, matchFunc selector.MatchFunc, middlewares ...KMiddleware) KMiddleware
SelectorServer creates a selector middleware for server-side. This helper function is still available for direct use if needed to wrap specific middlewares.
func Validate ¶
func Validate(ms []KMiddleware, validator *validatorv1.Validator) []KMiddleware
Validate is a middleware validator. Deprecated: use ValidateServer
func ValidateServer ¶ added in v0.0.12
func ValidateServer(ms []KMiddleware, validator *validatorv1.Validator) []KMiddleware
type Name ¶ added in v0.2.6
type Name string
Name is the name of a middleware.
const ( Jwt Name = "jwt" CircuitBreaker Name = "circuit_breaker" Logging Name = "logging" Metadata Name = "metadata" RateLimiter Name = "rate_limiter" Tracing Name = "tracing" Validator Name = "validator" Optimize Name = "optimize" Recovery Name = "recovery" Selector Name = "selector" DeclarativeSecurity Name = "declarative_security" Cors Name = "cors" )
Middleware names.
type Option ¶ added in v0.1.0
Option is a functional option for configuring middleware options.
func WithCarrier ¶ added in v0.2.6
WithCarrier sets the full Carrier for the middleware options.
func WithClaimsFactory ¶ added in v0.2.13
WithClaimsFactory provides a function that generates JWT claims. This is the recommended way to create dynamic claims for each token.
func WithClientCarrier ¶ added in v0.2.13
func WithClientCarrier(clientMiddlewares map[string]KMiddleware) Option
WithClientCarrier sets the client middlewares map in the Carrier.
func WithMatchFunc ¶ added in v0.1.29
WithMatchFunc sets the MatchFunc for the selector middleware.
func WithServerCarrier ¶ added in v0.2.13
func WithServerCarrier(serverMiddlewares map[string]KMiddleware) Option
WithServerCarrier sets the server middlewares map in the Carrier.
func WithSigningMethod ¶ added in v0.2.13
func WithSigningMethod(method jwt.SigningMethod) Option
WithSigningMethod sets the signing method to be used for JWT tokens. If not provided, the default from the configuration will be used.
func WithSubjectFactory ¶ added in v0.2.13
WithSubjectFactory provides a function that generates the JWT 'subject' (sub) claim. This is the recommended way to provide a meaningful user identifier for the token.
type Options ¶ added in v0.1.56
type Options struct {
Logger log.Logger
MatchFunc selector.MatchFunc
Carrier *Carrier
Options []Option
ClaimsFactory func() jwt.Claims
SubjectFactory func() string
SigningMethod jwt.SigningMethod
}
Options holds common options that have been resolved once at the top level. These options are then passed down to individual middleware factory functions.
func FromOptions ¶ added in v0.2.6
FromOptions resolves common options from a slice of generic Option.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cors implements CORS middleware for the framework.
|
Package cors implements CORS middleware for the framework. |
|
Package validate implements the functions, types, and interfaces for the module.
|
Package validate implements the functions, types, and interfaces for the module. |