Documentation
¶
Index ¶
- Constants
- Variables
- func NewChiMuxModule() modular.Module
- type BasicRouter
- type ChiMuxConfig
- type ChiMuxModule
- func (m *ChiMuxModule) ChiRouter() chi.Router
- func (m *ChiMuxModule) Connect(pattern string, h http.HandlerFunc)
- func (m *ChiMuxModule) Constructor() modular.ModuleConstructor
- func (m *ChiMuxModule) Delete(pattern string, handler http.HandlerFunc)
- func (m *ChiMuxModule) Dependencies() []string
- func (m *ChiMuxModule) Get(pattern string, handler http.HandlerFunc)
- func (m *ChiMuxModule) GetTenantConfig(tenantID modular.TenantID) *ChiMuxConfig
- func (m *ChiMuxModule) Group(fn func(chi.Router)) chi.Router
- func (m *ChiMuxModule) Handle(pattern string, handler http.Handler)
- func (m *ChiMuxModule) HandleFunc(pattern string, handler http.HandlerFunc)
- func (m *ChiMuxModule) Head(pattern string, handler http.HandlerFunc)
- func (m *ChiMuxModule) Init(app modular.Application) error
- func (m *ChiMuxModule) Match(rctx *chi.Context, method, path string) bool
- func (m *ChiMuxModule) Method(method, pattern string, h http.Handler)
- func (m *ChiMuxModule) MethodFunc(method, pattern string, h http.HandlerFunc)
- func (m *ChiMuxModule) MethodNotAllowed(h http.HandlerFunc)
- func (m *ChiMuxModule) Middlewares() chi.Middlewares
- func (m *ChiMuxModule) Mount(pattern string, handler http.Handler)
- func (m *ChiMuxModule) Name() string
- func (m *ChiMuxModule) NotFound(h http.HandlerFunc)
- func (m *ChiMuxModule) OnTenantRegistered(tenantID modular.TenantID)
- func (m *ChiMuxModule) OnTenantRemoved(tenantID modular.TenantID)
- func (m *ChiMuxModule) Options(pattern string, handler http.HandlerFunc)
- func (m *ChiMuxModule) Patch(pattern string, handler http.HandlerFunc)
- func (m *ChiMuxModule) Post(pattern string, handler http.HandlerFunc)
- func (m *ChiMuxModule) ProvidesServices() []modular.ServiceProvider
- func (m *ChiMuxModule) Put(pattern string, handler http.HandlerFunc)
- func (m *ChiMuxModule) RegisterConfig(app modular.Application) error
- func (m *ChiMuxModule) RequiresServices() []modular.ServiceDependency
- func (m *ChiMuxModule) Route(pattern string, fn func(chi.Router)) chi.Router
- func (m *ChiMuxModule) Routes() []chi.Route
- func (m *ChiMuxModule) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *ChiMuxModule) Start(context.Context) error
- func (m *ChiMuxModule) Stop(context.Context) error
- func (m *ChiMuxModule) Trace(pattern string, h http.HandlerFunc)
- func (m *ChiMuxModule) Use(middlewares ...func(http.Handler) http.Handler)
- func (m *ChiMuxModule) With(middlewares ...func(http.Handler) http.Handler) chi.Router
- type ChiRouterService
- type Middleware
- type MiddlewareProvider
- type Router
- type RouterService
Constants ¶
const ModuleName = "chimux"
ModuleName is the name of this module
const ServiceName = "chimux.router"
ServiceName is the name of the service provided by this module (the chi router)
Variables ¶
var ( // ErrRequiresTenantApplication is returned when the module is initialized with a non-tenant application ErrRequiresTenantApplication = errors.New("chimux module requires a TenantApplication") )
Error definitions
Functions ¶
func NewChiMuxModule ¶
NewChiMuxModule creates a new instance of the chimux module
Types ¶
type BasicRouter ¶ added in v1.0.2
type BasicRouter interface {
// HTTP method handlers
Get(pattern string, handler http.HandlerFunc)
Post(pattern string, handler http.HandlerFunc)
Put(pattern string, handler http.HandlerFunc)
Delete(pattern string, handler http.HandlerFunc)
Patch(pattern string, handler http.HandlerFunc)
Head(pattern string, handler http.HandlerFunc)
Options(pattern string, handler http.HandlerFunc)
// Generic handlers
Handle(pattern string, handler http.Handler)
HandleFunc(pattern string, handler http.HandlerFunc)
// Mounting and middleware
Mount(pattern string, handler http.Handler)
Use(middlewares ...func(http.Handler) http.Handler)
// HTTP handler
ServeHTTP(w http.ResponseWriter, r *http.Request)
}
BasicRouter defines the essential router interface that most modules need This interface avoids the Route/Group methods that are problematic for interface abstraction
type ChiMuxConfig ¶
type ChiMuxConfig struct {
AllowedOrigins []string `yaml:"allowed_origins" default:"[\"*\"]" desc:"List of allowed origins for CORS requests."` // List of allowed origins for CORS requests.
AllowedMethods []string `yaml:"allowed_methods" default:"[\"GET\",\"POST\",\"PUT\",\"DELETE\",\"OPTIONS\"]" desc:"List of allowed HTTP methods."` // List of allowed HTTP methods.
AllowedHeaders []string `` // List of allowed request headers.
/* 152-byte string literal not displayed */
AllowCredentials bool `yaml:"allow_credentials" default:"false" desc:"Allow credentials in CORS requests."` // Allow credentials in CORS requests.
MaxAge int `yaml:"max_age" default:"300" desc:"Maximum age for CORS preflight cache in seconds."` // Maximum age for CORS preflight cache in seconds.
Timeout int `yaml:"timeout" default:"60000" desc:"Default request timeout."` // Default request timeout.
BasePath string `yaml:"basepath" desc:"A base path prefix for all routes registered through this module."` // A base path prefix for all routes registered through this module.
}
ChiMuxConfig holds the configuration for the chimux module
func (*ChiMuxConfig) Validate ¶
func (c *ChiMuxConfig) Validate() error
Validate implements the modular.ConfigValidator interface
type ChiMuxModule ¶
type ChiMuxModule struct {
// contains filtered or unexported fields
}
ChiMuxModule represents the chimux module
func (*ChiMuxModule) ChiRouter ¶
func (m *ChiMuxModule) ChiRouter() chi.Router
ChiRouter returns the underlying chi.Router instance
func (*ChiMuxModule) Connect ¶ added in v1.0.2
func (m *ChiMuxModule) Connect(pattern string, h http.HandlerFunc)
func (*ChiMuxModule) Constructor ¶
func (m *ChiMuxModule) Constructor() modular.ModuleConstructor
Constructor provides a dependency injection constructor for the module
func (*ChiMuxModule) Delete ¶
func (m *ChiMuxModule) Delete(pattern string, handler http.HandlerFunc)
Delete registers a DELETE handler for the pattern
func (*ChiMuxModule) Dependencies ¶
func (m *ChiMuxModule) Dependencies() []string
Dependencies returns the names of modules this module depends on
func (*ChiMuxModule) Get ¶
func (m *ChiMuxModule) Get(pattern string, handler http.HandlerFunc)
Get registers a GET handler for the pattern
func (*ChiMuxModule) GetTenantConfig ¶
func (m *ChiMuxModule) GetTenantConfig(tenantID modular.TenantID) *ChiMuxConfig
GetTenantConfig retrieves the loaded configuration for a specific tenant Returns the base config if no specific tenant config is found.
func (*ChiMuxModule) Group ¶ added in v1.0.2
func (m *ChiMuxModule) Group(fn func(chi.Router)) chi.Router
func (*ChiMuxModule) Handle ¶
func (m *ChiMuxModule) Handle(pattern string, handler http.Handler)
Handle registers a handler for a specific pattern
func (*ChiMuxModule) HandleFunc ¶
func (m *ChiMuxModule) HandleFunc(pattern string, handler http.HandlerFunc)
HandleFunc registers a handler function for a specific pattern
func (*ChiMuxModule) Head ¶
func (m *ChiMuxModule) Head(pattern string, handler http.HandlerFunc)
Head registers a HEAD handler for the pattern
func (*ChiMuxModule) Init ¶
func (m *ChiMuxModule) Init(app modular.Application) error
Init initializes the module
func (*ChiMuxModule) Match ¶ added in v1.0.2
func (m *ChiMuxModule) Match(rctx *chi.Context, method, path string) bool
func (*ChiMuxModule) Method ¶ added in v1.0.2
func (m *ChiMuxModule) Method(method, pattern string, h http.Handler)
func (*ChiMuxModule) MethodFunc ¶ added in v1.0.2
func (m *ChiMuxModule) MethodFunc(method, pattern string, h http.HandlerFunc)
func (*ChiMuxModule) MethodNotAllowed ¶ added in v1.0.2
func (m *ChiMuxModule) MethodNotAllowed(h http.HandlerFunc)
func (*ChiMuxModule) Middlewares ¶ added in v1.0.2
func (m *ChiMuxModule) Middlewares() chi.Middlewares
func (*ChiMuxModule) Mount ¶
func (m *ChiMuxModule) Mount(pattern string, handler http.Handler)
Mount attaches another http.Handler at the given pattern
func (*ChiMuxModule) Name ¶
func (m *ChiMuxModule) Name() string
Name returns the name of the module
func (*ChiMuxModule) NotFound ¶ added in v1.0.2
func (m *ChiMuxModule) NotFound(h http.HandlerFunc)
func (*ChiMuxModule) OnTenantRegistered ¶
func (m *ChiMuxModule) OnTenantRegistered(tenantID modular.TenantID)
OnTenantRegistered is called when a new tenant is registered
func (*ChiMuxModule) OnTenantRemoved ¶
func (m *ChiMuxModule) OnTenantRemoved(tenantID modular.TenantID)
OnTenantRemoved is called when a tenant is removed
func (*ChiMuxModule) Options ¶
func (m *ChiMuxModule) Options(pattern string, handler http.HandlerFunc)
Options registers an OPTIONS handler for the pattern
func (*ChiMuxModule) Patch ¶
func (m *ChiMuxModule) Patch(pattern string, handler http.HandlerFunc)
Patch registers a PATCH handler for the pattern
func (*ChiMuxModule) Post ¶
func (m *ChiMuxModule) Post(pattern string, handler http.HandlerFunc)
Post registers a POST handler for the pattern
func (*ChiMuxModule) ProvidesServices ¶
func (m *ChiMuxModule) ProvidesServices() []modular.ServiceProvider
ProvidesServices declares services provided by this module
func (*ChiMuxModule) Put ¶
func (m *ChiMuxModule) Put(pattern string, handler http.HandlerFunc)
Put registers a PUT handler for the pattern
func (*ChiMuxModule) RegisterConfig ¶
func (m *ChiMuxModule) RegisterConfig(app modular.Application) error
RegisterConfig registers the module's configuration structure
func (*ChiMuxModule) RequiresServices ¶
func (m *ChiMuxModule) RequiresServices() []modular.ServiceDependency
RequiresServices declares services required by this module
func (*ChiMuxModule) Routes ¶ added in v1.0.2
func (m *ChiMuxModule) Routes() []chi.Route
Routes returns the router's route information (part of chi.Routes interface)
func (*ChiMuxModule) ServeHTTP ¶
func (m *ChiMuxModule) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface to properly handle base path prefixing
func (*ChiMuxModule) Start ¶
func (m *ChiMuxModule) Start(context.Context) error
Start performs startup logic for the module
func (*ChiMuxModule) Stop ¶
func (m *ChiMuxModule) Stop(context.Context) error
Stop performs shutdown logic for the module
func (*ChiMuxModule) Trace ¶ added in v1.0.2
func (m *ChiMuxModule) Trace(pattern string, h http.HandlerFunc)
type ChiRouterService ¶
type ChiRouterService interface {
// Direct access to the underlying chi router
ChiRouter() chi.Router
}
ChiRouterService defines the interface for working with the Chi router
type Middleware ¶
Middleware is an alias for the chi middleware handler function
type MiddlewareProvider ¶
type MiddlewareProvider interface {
ProvideMiddleware() []Middleware
}
MiddlewareProvider defines a service that provides middleware for the chimux router
type Router ¶
type Router interface {
BasicRouter
chi.Router // Embed Chi's actual Router interface
}
Router extends BasicRouter with Chi's actual interface This allows modules that need Route/Group to access them directly
type RouterService ¶
type RouterService = BasicRouter
RouterService is an alias for BasicRouter for modules that don't need Route/Group