webhookd/pkg/api/router.go
Nicolas Carlier 6b3623f67a feat(api): refactore router
- Simplify router
- Single routes onfiguration file
- Improve HTTP logger
2021-07-11 13:09:44 +02:00

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
}