feat(api): add new route for listing routes by provider

This commit is contained in:
yusing 2025-05-10 12:58:37 +08:00
parent 48823a860f
commit 26938eb6ed
2 changed files with 11 additions and 0 deletions

View file

@ -20,6 +20,7 @@ import (
const (
ListRoute = "route"
ListRoutes = "routes"
ListRoutesByProvider = "routes_by_provider"
ListFiles = "files"
ListMiddlewares = "middlewares"
ListMiddlewareTraces = "middleware_trace"
@ -48,6 +49,8 @@ func List(cfg config.ConfigInstance, w http.ResponseWriter, r *http.Request) {
}
case ListRoutes:
gphttp.RespondJSON(w, r, routes.ByAlias(route.RouteType(r.FormValue("type"))))
case ListRoutesByProvider:
gphttp.RespondJSON(w, r, routes.ByProvider())
case ListFiles:
listFiles(w, r)
case ListMiddlewares:

View file

@ -135,3 +135,11 @@ func ByAlias(typeFilter ...route.RouteType) map[string]Route {
}
return rts
}
func ByProvider() map[string][]Route {
rts := make(map[string][]Route)
for _, r := range HTTP.Iter {
rts[r.ProviderName()] = append(rts[r.ProviderName()], r)
}
return rts
}