mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 17:28:31 +02:00
refactor(routes): replace route retrieval with GetIncludeExcluded
- Updated route retrieval in the API and idle watcher to use GetIncludeExcluded, allowing for the inclusion of excluded routes. - Simplified the route status aggregation logic by directly using GetIncludeExcluded for display name resolution. - Removed redundant code that separately handled excluded routes, streamlining the route management process.
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
statequery "github.com/yusing/godoxy/internal/config/query"
|
|
||||||
"github.com/yusing/godoxy/internal/route/routes"
|
"github.com/yusing/godoxy/internal/route/routes"
|
||||||
apitypes "github.com/yusing/goutils/apitypes"
|
apitypes "github.com/yusing/goutils/apitypes"
|
||||||
)
|
)
|
||||||
@@ -33,17 +32,10 @@ func Route(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
route, ok := routes.Get(request.Which)
|
route, ok := routes.GetIncludeExcluded(request.Which)
|
||||||
if ok {
|
if ok {
|
||||||
c.JSON(http.StatusOK, route)
|
c.JSON(http.StatusOK, route)
|
||||||
return
|
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)
|
c.JSON(http.StatusNotFound, nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ func NewWatcher(parent task.Parent, r types.Route, cfg *types.IdlewatcherConfig)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
depRoute, ok = routes.Get(dep)
|
depRoute, ok = routes.GetIncludeExcluded(dep)
|
||||||
if !ok {
|
if !ok {
|
||||||
depErrors.Addf("dependency %q not found", dep)
|
depErrors.Addf("dependency %q not found", dep)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -130,17 +130,10 @@ func (rs RouteStatuses) aggregate(limit int, offset int) Aggregated {
|
|||||||
up, down, idle, latency := rs.calculateInfo(statuses)
|
up, down, idle, latency := rs.calculateInfo(statuses)
|
||||||
|
|
||||||
displayName := alias
|
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
|
status := types.StatusUnknown
|
||||||
if r != nil {
|
r, ok := routes.GetIncludeExcluded(alias)
|
||||||
|
if ok {
|
||||||
|
displayName = r.DisplayName()
|
||||||
mon := r.HealthMonitor()
|
mon := r.HealthMonitor()
|
||||||
if mon != nil {
|
if mon != nil {
|
||||||
status = mon.Status()
|
status = mon.Status()
|
||||||
|
|||||||
@@ -78,3 +78,14 @@ func Get(alias string) (types.Route, bool) {
|
|||||||
}
|
}
|
||||||
return nil, false
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user