24 lines
443 B
Go
24 lines
443 B
Go
|
package middlewares
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
type MiddlewareChains struct {
|
||
|
handlers []http.Handler
|
||
|
}
|
||
|
|
||
|
func (mc *MiddlewareChains) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||
|
for _, h := range mc.handlers {
|
||
|
h.ServeHTTP(rw, r)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithLogger(handler http.Handler, l *logrus.Logger) *MiddlewareChains {
|
||
|
return &MiddlewareChains{
|
||
|
handlers: []http.Handler{handler, &LoggerMiddleware{l}},
|
||
|
}
|
||
|
}
|