Documentation
¶
Index ¶
- func DropCoreMigrations(ctx context.Context, logger models.Logger, dbProvider string, db bun.IDB) error
- func InitCoreServices(config *models.Config, db bun.IDB, serviceRegistry models.ServiceRegistry) *coreservices.CoreServices
- func InitDatabase(config *models.Config, logger models.Logger, logLevel string) (bun.IDB, error)
- func InitEventBus(config *models.Config) (models.EventBus, error)
- func InitLogger(config *models.Config) models.Logger
- func RunCoreMigrations(ctx context.Context, logger models.Logger, dbProvider string, db bun.IDB) error
- type Auth
- func (auth *Auth) ClosePlugins() error
- func (auth *Auth) DropCoreMigrations(ctx context.Context) error
- func (auth *Auth) GetAccountService() services.AccountService
- func (auth *Auth) GetJWTService() services.JWTService
- func (auth *Auth) GetMailerService() services.MailerService
- func (auth *Auth) GetPasswordService() services.PasswordService
- func (auth *Auth) GetSessionService() services.SessionService
- func (auth *Auth) GetTokenService() services.TokenService
- func (auth *Auth) GetUserIDFromContext(ctx context.Context) (string, bool)
- func (auth *Auth) GetUserIDFromRequest(req *http.Request) (string, bool)
- func (auth *Auth) GetUserService() services.UserService
- func (auth *Auth) GetVerificationService() services.VerificationService
- func (auth *Auth) Handler() http.Handler
- func (auth *Auth) RegisterCustomRoute(route models.Route)
- func (auth *Auth) RegisterCustomRoutes(routes []models.Route)
- func (auth *Auth) RegisterHook(hook models.Hook)
- func (auth *Auth) RegisterHooks(hooks []models.Hook)
- func (auth *Auth) RegisterMiddleware(middleware ...func(http.Handler) http.Handler)
- func (auth *Auth) RegisterRoute(route models.Route)
- func (auth *Auth) RegisterRoutes(routes []models.Route)
- func (auth *Auth) RunCoreMigrations(ctx context.Context) error
- type AuthConfig
- type HookErrorMode
- type HookType
- type Router
- func (r *Router) Get() chi.Router
- func (r *Router) Handler() http.Handler
- func (r *Router) RegisterCustomRoute(route models.Route)
- func (r *Router) RegisterCustomRoutes(routes []models.Route)
- func (r *Router) RegisterHook(hook models.Hook)
- func (r *Router) RegisterHooks(hooks []models.Hook)
- func (r *Router) RegisterMiddleware(middleware ...func(http.Handler) http.Handler)
- func (r *Router) RegisterRoute(route models.Route)
- func (r *Router) RegisterRoutes(routes []models.Route)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) SetRouteMetadataFromConfig(routeMetadata map[string]map[string]any)
- type RouterOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DropCoreMigrations ¶
func InitCoreServices ¶
func InitCoreServices(config *models.Config, db bun.IDB, serviceRegistry models.ServiceRegistry) *coreservices.CoreServices
func InitDatabase ¶
InitDatabase creates a Bun DB connection based on provider
func InitEventBus ¶
InitEventBus creates an event bus based on the configuration
func InitLogger ¶
InitLogger initializes the logger based on configuration
Types ¶
type Auth ¶
type Auth struct {
ServiceRegistry models.ServiceRegistry
PluginRegistry models.PluginRegistry
Api internal.CoreAPI
// contains filtered or unexported fields
}
Auth is a composition root and entry point for the authentication framework.
func New ¶
func New(authConfig *AuthConfig) *Auth
New creates a new Auth instance using the provided config and plugins. Handles plugin registration, migrations, and initialization in unified way. Works identically whether plugins are manually instantiated or built from config.
func (*Auth) ClosePlugins ¶
ClosePlugins calls Close for all registered plugins
func (*Auth) GetAccountService ¶
func (auth *Auth) GetAccountService() services.AccountService
func (*Auth) GetJWTService ¶
func (auth *Auth) GetJWTService() services.JWTService
func (*Auth) GetMailerService ¶
func (auth *Auth) GetMailerService() services.MailerService
func (*Auth) GetPasswordService ¶
func (auth *Auth) GetPasswordService() services.PasswordService
func (*Auth) GetSessionService ¶
func (auth *Auth) GetSessionService() services.SessionService
func (*Auth) GetTokenService ¶
func (auth *Auth) GetTokenService() services.TokenService
func (*Auth) GetUserIDFromContext ¶
GetUserIDFromContext retrieves the user ID from a context. Returns the user ID and a boolean indicating whether it was found. This is a convenience wrapper around models.GetUserIDFromContext to avoid requiring application code to import the models package.
func (*Auth) GetUserIDFromRequest ¶
GetUserIDFromRequest retrieves the user ID from an HTTP request's context. Returns the user ID and a boolean indicating whether it was found. This is a convenience wrapper around models.GetUserIDFromRequest to avoid requiring application code to import the models package.
func (*Auth) GetUserService ¶
func (auth *Auth) GetUserService() services.UserService
func (*Auth) GetVerificationService ¶
func (auth *Auth) GetVerificationService() services.VerificationService
func (*Auth) Handler ¶
Handler returns the HTTP handler that serves all authentication routes and hooks. It registers routes and hooks from all plugins with the router. This is the entry point for HTTP traffic.
func (*Auth) RegisterCustomRoute ¶
RegisterCustomRoute registers a single custom route without the basePath prefix This is useful for application routes that should not be under the auth basePath
func (*Auth) RegisterCustomRoutes ¶
RegisterCustomRoutes registers multiple custom routes without the basePath prefix This is useful for application routes that should not be under the auth basePath
func (*Auth) RegisterHook ¶
RegisterHook registers a single hook to the router. Hooks allow developers to intercept and modify requests/responses at various stages of the request lifecycle (OnRequest, Before, After, OnResponse).
func (*Auth) RegisterHooks ¶
RegisterHooks registers multiple hooks to the router. Hooks allow developers to intercept and modify requests/responses at various stages of the request lifecycle (OnRequest, Before, After, OnResponse).
func (*Auth) RegisterMiddleware ¶
RegisterMiddleware registers middleware to the chi router. Middleware should be registered before calling Handler().
func (*Auth) RegisterRoute ¶
RegisterRoute registers a single route with the basePath prefix
func (*Auth) RegisterRoutes ¶
RegisterRoutes registers multiple routes with the basePath prefix
type HookErrorMode ¶
type HookErrorMode string
HookErrorMode defines how the router handles errors from hook handlers
const ( // HookErrorModeContinue logs errors but continues to next hook (default) HookErrorModeContinue HookErrorMode = "error-log-continue" // HookErrorModeFailFast logs error and sets ctx.Handled=true to skip remaining hooks in current stage HookErrorModeFailFast HookErrorMode = "error-log-fail-fast" // HookErrorModeSilent silently ignores errors without logging HookErrorModeSilent HookErrorMode = "error-silent" )
type HookType ¶
type HookType string
HookErrorMode defines how the router handles errors from hook handlers
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router wraps chi.Router and manages hooks for the request lifecycle
func NewRouter ¶
NewRouter creates a new Router with Chi as the underlying router opts can be nil to use default options
func (*Router) Handler ¶
Handler returns the configured HTTP handler - the Router with hook middleware
func (*Router) RegisterCustomRoute ¶
RegisterCustomRoute registers a custom route without the basePath prefix This is useful for application routes that should not be under the auth basePath
func (*Router) RegisterCustomRoutes ¶
RegisterCustomRoutes registers multiple custom routes without the basePath prefix This is useful for application routes that should not be under the auth basePath
func (*Router) RegisterHook ¶
RegisterHook registers a single hook
func (*Router) RegisterHooks ¶
RegisterHooks registers multiple hooks
func (*Router) RegisterMiddleware ¶
RegisterMiddleware registers global middleware with Chi
func (*Router) RegisterRoute ¶
RegisterRoute registers a single route with Chi
func (*Router) RegisterRoutes ¶
RegisterRoutes registers multiple routes with an optional base path
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements http.Handler for testing and direct use
func (*Router) SetRouteMetadataFromConfig ¶
SetRouteMetadataFromConfig sets route metadata mappings from RouteMappings. This populates the internal metadata map used to assign ctx.Route.Metadata["plugins"] during request handling. Supports both static and dynamic (parameterized) routes. Format: routeMetadata["METHOD:path"] = {"plugins": ["plugin1", "plugin2"], ...} Examples:
- Static route: "GET:/me" -> plugins for GET /me
- Dynamic route: "POST:/oauth2/callback/{provider}" -> plugins for POST /oauth2/callback/{provider} (matches any provider value)
- Multi-param: "GET:/users/{id}/posts/{postId}" -> plugins for any GET request with that pattern
Dynamic routes use {paramName} syntax and match any actual parameter value at that position. At request time, the router first tries exact path matching, then falls back to pattern matching.
type RouterOptions ¶
type RouterOptions struct {
// AsyncHookTimeout is the timeout for async hook execution (default: 30 seconds)
// If a hook takes longer than this, it will be cancelled
AsyncHookTimeout time.Duration
// HookErrorMode defines how errors from hooks are handled (default: HookErrorModeContinue)
// Controls whether errors cause early exit, silent ignoring, or just logging
HookErrorMode HookErrorMode
}
RouterOptions contains configuration options for the Router
func DefaultRouterOptions ¶
func DefaultRouterOptions() *RouterOptions
DefaultRouterOptions returns router options with sensible defaults