Documentation
¶
Index ¶
- Variables
- func ProvideAsMiddleware(provider any, anns ...fx.Annotation) fx.Option
- func SetPrincipal(ctx context.Context, principal Principal) context.Context
- type AuthNMiddleware
- type AuthNProvider
- type BaseMiddleware
- type DatabaseBunTrxMiddleware
- type DatabaseGORMTrxMiddleware
- type KeyValueContextMiddleware
- type Middleware
- type MiddlewarePriority
- type Middlewares
- type PanicRecoveryMiddleware
- type Principal
- type PrincipalType
- type RequestLoggerMiddleware
Constants ¶
This section is empty.
Variables ¶
var AuthNExcludedCtxKey = context.CtxKey("authn_excluded")
var ErrInvalidToken = errors.Newf("AUTHN_TOKEN_NOT_VALID", "token is not valid")
var FxExport = fx.Options( fx.Provide(NewMiddlewares), ProvideAsMiddleware(NewKeyValueContextMiddleware), ProvideAsMiddleware(NewRequestLogger), ProvideAsMiddleware(NewPanicRecovery), )
var FxExportAuthN = ProvideAsMiddleware(NewAuthN)
var FxExportDBBun = ProvideAsMiddleware(NewDatabaseBunTrxMiddleware)
var FxExportDBGORM = ProvideAsMiddleware(NewDatabaseGORMTrx)
var PrincipalCtxKey = context.CtxKey("_fw_authn_principal")
Functions ¶
func ProvideAsMiddleware ¶
func ProvideAsMiddleware(provider any, anns ...fx.Annotation) fx.Option
Types ¶
type AuthNMiddleware ¶
type AuthNMiddleware struct {
BaseMiddleware
// contains filtered or unexported fields
}
AuthNMiddleware The exclusions are implemented as a map from path prefix to list of methods. If the list of methods is empty, then all methods are excluded for the path prefix acting as map key
func NewAuthN ¶
func NewAuthN( conf config.Config, lf log.LoggerFactory, provider AuthNProvider, ) *AuthNMiddleware
func (*AuthNMiddleware) ExcludePrefix ¶
func (m *AuthNMiddleware) ExcludePrefix(pathPrefix string)
ExcludePrefix excludes the given path prefix from authentication for all methods. Internally, this method attempts to add the empty list to the exclusion map. If the path prefix was already excluded for specific methods, then the function will make the list nil to exclude all methods.
func (*AuthNMiddleware) ExcludePrefixAndMethods ¶
func (m *AuthNMiddleware) ExcludePrefixAndMethods(pathPrefix string, methods ...string)
ExcludePrefixAndMethods excludes the given path prefix from authentication for the given methods. There must be at least one given method. Internally, this method attempts to append the given methods to the methods list already present in the exclusion map for the given path prefix. If the already present method list is of length zero, it means the path prefix was already excluded for all methods, and the function doesn't do anything further.
func (*AuthNMiddleware) Handle ¶ added in v0.7.0
func (m *AuthNMiddleware) Handle(next http.Handler) http.Handler
func (*AuthNMiddleware) Priority ¶
func (m *AuthNMiddleware) Priority() MiddlewarePriority
type AuthNProvider ¶
type DatabaseBunTrxMiddleware ¶ added in v0.7.0
type DatabaseBunTrxMiddleware struct {
BaseMiddleware
// contains filtered or unexported fields
}
func NewDatabaseBunTrxMiddleware ¶ added in v0.7.0
func NewDatabaseBunTrxMiddleware( conf config.Config, lf log.LoggerFactory, db *bun.DB, ) *DatabaseBunTrxMiddleware
func (*DatabaseBunTrxMiddleware) Handle ¶ added in v0.7.0
func (m *DatabaseBunTrxMiddleware) Handle(next http.Handler) http.Handler
func (*DatabaseBunTrxMiddleware) Priority ¶ added in v0.7.0
func (m *DatabaseBunTrxMiddleware) Priority() MiddlewarePriority
type DatabaseGORMTrxMiddleware ¶ added in v0.7.0
type DatabaseGORMTrxMiddleware struct {
BaseMiddleware
// contains filtered or unexported fields
}
func NewDatabaseGORMTrx ¶ added in v0.7.0
func NewDatabaseGORMTrx( conf config.Config, lf log.LoggerFactory, db database.DB, ) *DatabaseGORMTrxMiddleware
func (*DatabaseGORMTrxMiddleware) Handle ¶ added in v0.7.0
func (m *DatabaseGORMTrxMiddleware) Handle(next http.Handler) http.Handler
func (*DatabaseGORMTrxMiddleware) Priority ¶ added in v0.7.0
func (m *DatabaseGORMTrxMiddleware) Priority() MiddlewarePriority
type KeyValueContextMiddleware ¶ added in v0.7.0
type KeyValueContextMiddleware struct {
BaseMiddleware
}
func NewKeyValueContextMiddleware ¶ added in v0.7.0
func NewKeyValueContextMiddleware( conf config.Config, lf log.LoggerFactory, ) *KeyValueContextMiddleware
func (*KeyValueContextMiddleware) Handle ¶ added in v0.7.0
func (m *KeyValueContextMiddleware) Handle(next http.Handler) http.Handler
func (*KeyValueContextMiddleware) Priority ¶ added in v0.7.0
func (m *KeyValueContextMiddleware) Priority() MiddlewarePriority
type Middleware ¶
type Middleware interface {
Priority() MiddlewarePriority
Handle(http.Handler) http.Handler
}
type MiddlewarePriority ¶
type MiddlewarePriority int
generate the stringer
const ( MiddlewarePriorityNotSet MiddlewarePriority = iota MiddlewarePriorityHighest MiddlewarePriority = iota * 1_000 MiddlewarePriorityBeforeMux MiddlewarePriorityBeforeMuxInclusive MiddlewarePriority = MiddlewarePriorityBeforeMux + 1 MiddlewarePriorityAfterMux MiddlewarePriority = iota * 1_000 MiddlewarePriorityAuthN MiddlewarePriorityAuthZ MiddlewarePriorityDefault // Max int value MiddlewarePriorityLowest MiddlewarePriority = MiddlewarePriority(int(^uint(0) >> 1)) )
func (MiddlewarePriority) String ¶ added in v0.7.0
func (i MiddlewarePriority) String() string
type Middlewares ¶
type Middlewares struct {
// contains filtered or unexported fields
}
func NewMiddlewares ¶
func NewMiddlewares(deps struct {
fx.In
LF log.LoggerFactory
Middlewares []Middleware `group:"rest_middlewares"`
}) Middlewares
func (Middlewares) Append ¶ added in v0.7.0
func (m Middlewares) Append(mw Middleware) Middlewares
func (Middlewares) Apply ¶ added in v0.7.0
func (m Middlewares) Apply(from MiddlewarePriority, to MiddlewarePriority, next http.Handler) http.Handler
Apply applies the middlewares in the given priority range [from, to) to the given handler, returning the wrapped handler
type PanicRecoveryMiddleware ¶
type PanicRecoveryMiddleware struct {
BaseMiddleware
}
func NewPanicRecovery ¶
func NewPanicRecovery( conf config.Config, lf log.LoggerFactory, ) *PanicRecoveryMiddleware
func (*PanicRecoveryMiddleware) Handle ¶ added in v0.7.0
func (m *PanicRecoveryMiddleware) Handle(next http.Handler) http.Handler
func (*PanicRecoveryMiddleware) Priority ¶
func (m *PanicRecoveryMiddleware) Priority() MiddlewarePriority
type Principal ¶
type Principal interface {
GetID() any
GetName() string
GetEmail() string
GetType() PrincipalType
}
func MustGetPrincipal ¶
type PrincipalType ¶
type PrincipalType string
type RequestLoggerMiddleware ¶
type RequestLoggerMiddleware struct {
BaseMiddleware
// contains filtered or unexported fields
}
func NewRequestLogger ¶
func NewRequestLogger(conf config.Config, lf log.LoggerFactory) *RequestLoggerMiddleware
func (*RequestLoggerMiddleware) Handle ¶ added in v0.7.0
func (m *RequestLoggerMiddleware) Handle(next http.Handler) http.Handler
func (*RequestLoggerMiddleware) Priority ¶
func (m *RequestLoggerMiddleware) Priority() MiddlewarePriority