http-boot-server/bootserver/middlewares/middlewarechain.go

24 lines
443 B
Go
Raw Normal View History

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}},
}
}