29 lines
530 B
Go
29 lines
530 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
api "fr.latosa-escrima/api"
|
|
)
|
|
|
|
type HandlerFunc func(w http.ResponseWriter, r *http.Request)
|
|
|
|
type Handler struct {
|
|
Handler HandlerFunc
|
|
Middleware func(http.Handler) http.Handler
|
|
}
|
|
|
|
func HandleRoutes(mux *http.ServeMux, routes map[string]Handler) {
|
|
for pattern, handler := range routes {
|
|
if handler.Middleware == nil {
|
|
mux.HandleFunc(pattern, handler.Handler)
|
|
} else {
|
|
api.HandleMiddlewareRoute(
|
|
pattern,
|
|
handler.Handler,
|
|
handler.Middleware,
|
|
mux,
|
|
)
|
|
}
|
|
}
|
|
}
|