mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 09:48:49 +02:00
feat(routes): enhance route retrieval with search functionality
- Added SearchRoute method to Config for searching routes by alias. - Updated Route function to check for excluded routes if the initial lookup fails, returning the found route or a 404 status accordingly.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
apitypes "github.com/yusing/go-proxy/internal/api/types"
|
apitypes "github.com/yusing/go-proxy/internal/api/types"
|
||||||
|
config "github.com/yusing/go-proxy/internal/config/types"
|
||||||
"github.com/yusing/go-proxy/internal/route/routes"
|
"github.com/yusing/go-proxy/internal/route/routes"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,7 +36,14 @@ func Route(c *gin.Context) {
|
|||||||
route, ok := routes.Get(request.Which)
|
route, ok := routes.Get(request.Which)
|
||||||
if ok {
|
if ok {
|
||||||
c.JSON(http.StatusOK, route)
|
c.JSON(http.StatusOK, route)
|
||||||
} else {
|
return
|
||||||
c.JSON(http.StatusNotFound, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// also search for excluded routes
|
||||||
|
route = config.GetInstance().SearchRoute(request.Which)
|
||||||
|
if route != nil {
|
||||||
|
c.JSON(http.StatusOK, route)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusNotFound, nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,15 @@ func (cfg *Config) RouteProviderList() []config.RouteProviderListResponse {
|
|||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cfg *Config) SearchRoute(alias string) types.Route {
|
||||||
|
for _, p := range cfg.providers.Range {
|
||||||
|
if r, ok := p.GetRoute(alias); ok {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (cfg *Config) Statistics() map[string]any {
|
func (cfg *Config) Statistics() map[string]any {
|
||||||
var rps, streams types.RouteStats
|
var rps, streams types.RouteStats
|
||||||
var total uint16
|
var total uint16
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/yusing/go-proxy/internal/notif"
|
"github.com/yusing/go-proxy/internal/notif"
|
||||||
"github.com/yusing/go-proxy/internal/proxmox"
|
"github.com/yusing/go-proxy/internal/proxmox"
|
||||||
"github.com/yusing/go-proxy/internal/serialization"
|
"github.com/yusing/go-proxy/internal/serialization"
|
||||||
|
"github.com/yusing/go-proxy/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -51,6 +52,7 @@ type (
|
|||||||
Reload() gperr.Error
|
Reload() gperr.Error
|
||||||
Statistics() map[string]any
|
Statistics() map[string]any
|
||||||
RouteProviderList() []RouteProviderListResponse
|
RouteProviderList() []RouteProviderListResponse
|
||||||
|
SearchRoute(alias string) types.Route
|
||||||
Context() context.Context
|
Context() context.Context
|
||||||
VerifyNewAgent(host string, ca agent.PEMPair, client agent.PEMPair, containerRuntime agent.ContainerRuntime) (int, gperr.Error)
|
VerifyNewAgent(host string, ca agent.PEMPair, client agent.PEMPair, containerRuntime agent.ContainerRuntime) (int, gperr.Error)
|
||||||
AutoCertProvider() *autocert.Provider
|
AutoCertProvider() *autocert.Provider
|
||||||
|
|||||||
Reference in New Issue
Block a user