Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Component = &component.Component{ Dependencies: component.Components{ http.Component, }, Init: component.StepFunc(func(container container.Container) error { return container.Provides( func(logger logger.Logger) chi.Router { router := chi.NewRouter() router.Use( middleware.Recoverer, middleware.RequestLogger(&middleware.DefaultLogFormatter{Logger: logger, NoColor: true}), ) return router }, func(router chi.Router) http.Router { return NewDecorator(router) }, ) }), PostExecute: component.StepFunc(func(container container.Container) error { return container.Invoke(func(r http.Router, server http.Server) { server.SetRouter(r) }) }), }
Component is a ready-to-use Compogo component that provides a chi router. It automatically:
- Creates a chi router with standard middleware (recoverer, compress, request logger)
- Provides the router as both chi.Router and http.Router
- Attaches the router to the HTTP server during Run phase
Usage:
compogo.WithComponents(
http.Component,
chi.Component,
// ... other components that need the router
)
Functions ¶
This section is empty.
Types ¶
type Decorator ¶
Decorator adapts a chi.Router to implement the http.Router interface. This allows any chi router to be used with Compogo's HTTP server component.
func NewDecorator ¶
NewDecorator creates a new Decorator wrapping the provided chi router.
func (*Decorator) Group ¶
Group implements http.Router.Group by creating a sub-router with inherited middleware. The provided function receives a wrapped http.Router that operates on the chi sub-router.
func (*Decorator) Route ¶
Route implements http.Router.Route by creating a new sub-router with the given prefix. The provided function receives a wrapped http.Router that operates on the chi sub-router.
func (*Decorator) Use ¶
func (d *Decorator) Use(middlewares ...http.Middleware)
Use implements http.Router.Use by converting Compogo middlewares to chi middlewares. It iterates through the provided middlewares and adds them to the underlying chi router.