webhookd/pkg/api/router.go

24 lines
445 B
Go

package api
import (
"net/http"
"github.com/ncarlier/webhookd/pkg/config"
)
// NewRouter creates router with declared routes
func NewRouter(conf *config.Config) *http.ServeMux {
router := http.NewServeMux()
// Register HTTP routes...
for _, route := range routes(conf) {
handler := route.HandlerFunc(conf)
for _, mw := range route.Middlewares {
handler = mw(handler)
}
router.Handle(route.Path, handler)
}
return router
}