diff --git a/internal/api/v1/route/route.go b/internal/api/v1/route/route.go index ff9d3e73..ed1a205a 100644 --- a/internal/api/v1/route/route.go +++ b/internal/api/v1/route/route.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/gin-gonic/gin" - statequery "github.com/yusing/godoxy/internal/config/query" "github.com/yusing/godoxy/internal/route/routes" apitypes "github.com/yusing/goutils/apitypes" ) @@ -33,17 +32,10 @@ func Route(c *gin.Context) { return } - route, ok := routes.Get(request.Which) + route, ok := routes.GetIncludeExcluded(request.Which) if ok { c.JSON(http.StatusOK, route) return } - - // also search for excluded routes - route = statequery.SearchRoute(request.Which) - if route != nil { - c.JSON(http.StatusOK, route) - return - } c.JSON(http.StatusNotFound, nil) } diff --git a/internal/idlewatcher/watcher.go b/internal/idlewatcher/watcher.go index e79ccc6f..5f43f9e5 100644 --- a/internal/idlewatcher/watcher.go +++ b/internal/idlewatcher/watcher.go @@ -173,7 +173,7 @@ func NewWatcher(parent task.Parent, r types.Route, cfg *types.IdlewatcherConfig) } if !ok { - depRoute, ok = routes.Get(dep) + depRoute, ok = routes.GetIncludeExcluded(dep) if !ok { depErrors.Addf("dependency %q not found", dep) continue diff --git a/internal/metrics/uptime/uptime.go b/internal/metrics/uptime/uptime.go index 3fa74b56..e3e2d2a1 100644 --- a/internal/metrics/uptime/uptime.go +++ b/internal/metrics/uptime/uptime.go @@ -130,17 +130,10 @@ func (rs RouteStatuses) aggregate(limit int, offset int) Aggregated { up, down, idle, latency := rs.calculateInfo(statuses) displayName := alias - r, ok := routes.Get(alias) - if !ok { - // also search for excluded routes - r, ok = routes.Excluded.Get(alias) - } - if r != nil { - displayName = r.DisplayName() - } - status := types.StatusUnknown - if r != nil { + r, ok := routes.GetIncludeExcluded(alias) + if ok { + displayName = r.DisplayName() mon := r.HealthMonitor() if mon != nil { status = mon.Status() diff --git a/internal/route/routes/routes.go b/internal/route/routes/routes.go index 61034610..fc8d39d9 100644 --- a/internal/route/routes/routes.go +++ b/internal/route/routes/routes.go @@ -78,3 +78,14 @@ func Get(alias string) (types.Route, bool) { } return nil, false } + +// GetIncludeExcluded returns the route with the given alias, including excluded routes. +func GetIncludeExcluded(alias string) (types.Route, bool) { + if r, ok := HTTP.Get(alias); ok { + return r, true + } + if r, ok := Stream.Get(alias); ok { + return r, true + } + return Excluded.Get(alias) +}