Proper routing sir
This commit is contained in:
25
backend/router.go
Normal file
25
backend/router.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
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 {
|
||||
HandleMiddlewareRoute(
|
||||
pattern,
|
||||
handler.Handler,
|
||||
handler.Middleware,
|
||||
mux,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user