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:
yusing
2025-09-13 23:58:38 +08:00
parent 1e9303b1ef
commit ef65481394
3 changed files with 21 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
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"
)
@@ -35,7 +36,14 @@ func Route(c *gin.Context) {
route, ok := routes.Get(request.Which)
if ok {
c.JSON(http.StatusOK, route)
} else {
c.JSON(http.StatusNotFound, nil)
return
}
// 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)
}