Backend file structure modifications, blogs routes ajustement

This commit is contained in:
gom-by
2025-01-15 15:17:41 +01:00
12 changed files with 329 additions and 221 deletions

28
backend/router.go Normal file
View File

@@ -0,0 +1,28 @@
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,
)
}
}
}