feat(http): allow passing middlewares via options
All checks were successful
arcad/edge/pipeline/head This commit looks good
All checks were successful
arcad/edge/pipeline/head This commit looks good
This commit is contained in:
@ -97,6 +97,10 @@ func NewHandler(funcs ...HandlerOptionFunc) *Handler {
|
||||
bus: opts.Bus,
|
||||
}
|
||||
|
||||
for _, middleware := range opts.HTTPMiddlewares {
|
||||
router.Use(middleware)
|
||||
}
|
||||
|
||||
router.Route("/edge", func(r chi.Router) {
|
||||
r.Route("/sdk", func(r chi.Router) {
|
||||
r.Get("/client.js", handler.handleSDKClient)
|
||||
|
@ -18,6 +18,7 @@ type HandlerOptions struct {
|
||||
UploadMaxFileSize int64
|
||||
HTTPClient *http.Client
|
||||
HTTPMounts []func(r chi.Router)
|
||||
HTTPMiddlewares []func(next http.Handler) http.Handler
|
||||
}
|
||||
|
||||
func defaultHandlerOptions() *HandlerOptions {
|
||||
@ -34,7 +35,8 @@ func defaultHandlerOptions() *HandlerOptions {
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: time.Second * 30,
|
||||
},
|
||||
HTTPMounts: make([]func(r chi.Router), 0),
|
||||
HTTPMounts: make([]func(r chi.Router), 0),
|
||||
HTTPMiddlewares: make([]func(http.Handler) http.Handler, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,3 +77,9 @@ func WithHTTPMounts(mounts ...func(r chi.Router)) HandlerOptionFunc {
|
||||
opts.HTTPMounts = mounts
|
||||
}
|
||||
}
|
||||
|
||||
func WithHTTPMiddlewares(middlewares ...func(http.Handler) http.Handler) HandlerOptionFunc {
|
||||
return func(opts *HandlerOptions) {
|
||||
opts.HTTPMiddlewares = middlewares
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user