router.go 445 B

1234567891011121314151617181920212223
  1. package api
  2. import (
  3. "net/http"
  4. "github.com/ncarlier/webhookd/pkg/config"
  5. )
  6. // NewRouter creates router with declared routes
  7. func NewRouter(conf *config.Config) *http.ServeMux {
  8. router := http.NewServeMux()
  9. // Register HTTP routes...
  10. for _, route := range routes(conf) {
  11. handler := route.HandlerFunc(conf)
  12. for _, mw := range route.Middlewares {
  13. handler = mw(handler)
  14. }
  15. router.Handle(route.Path, handler)
  16. }
  17. return router
  18. }