Documentation
¶
Index ¶
- Constants
- func NewChiMuxModule() modular.Module
- type ChiMuxConfig
- type ChiMuxModule
- func (m *ChiMuxModule) ChiRouter() chi.Router
- 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) 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) Mount(pattern string, handler http.Handler)
- func (m *ChiMuxModule) Name() string
- 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(r Router))
- 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) Use(middleware ...func(http.Handler) http.Handler)
- 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 ¶
This section is empty.
Functions ¶
func NewChiMuxModule ¶
NewChiMuxModule creates a new instance of the chimux module
Types ¶
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) 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)
RouterService interface implementation 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) 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) 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) 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) Route ¶
func (m *ChiMuxModule) Route(pattern string, fn func(r Router))
Route creates a new sub-router for the given pattern
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
type ChiRouterService ¶
type ChiRouterService interface {
RouterService
ChiRouter() chi.Router
}
ChiRouterService extends RouterService with methods to access the underlying 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 RouterService ¶
type RouterService interface {
// Standard 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)
// Route creates a new sub-router for the given pattern
Route(pattern string, fn func(r Router))
// Mount attaches another http.Handler at the given pattern
Mount(pattern string, handler http.Handler)
// Use appends middleware to the chain
Use(middleware ...func(http.Handler) http.Handler)
// Handle registers a handler for a specific pattern
Handle(pattern string, handler http.Handler)
// HandleFunc registers a handler function for a specific pattern
HandleFunc(pattern string, handler http.HandlerFunc)
}
RouterService defines the interface for working with the Chi router