GoDoxy/internal/route/routes/routes.go
yusing 1fe21b84eb refactor: unify route handling by consolidating route query methods with Pool
- Replaced direct calls to routequery with a new routes package for better organization and maintainability.
- Updated various components to utilize the new routes methods for fetching health information, homepage configurations, and route aliases.
- Enhanced the overall structure of the routing logic to improve clarity and reduce redundancy.
2025-04-17 14:44:12 +08:00

49 lines
780 B
Go

package routes
import (
"github.com/yusing/go-proxy/internal/utils/pool"
)
var (
HTTP = pool.New[HTTPRoute]("http_routes")
Stream = pool.New[StreamRoute]("stream_routes")
)
func Iter(yield func(alias string, r Route) bool) {
for k, r := range HTTP.Iter {
if !yield(k, r) {
break
}
}
for k, r := range Stream.Iter {
if !yield(k, r) {
break
}
}
}
func NumRoutes() int {
return HTTP.Size() + Stream.Size()
}
func Clear() {
HTTP.Clear()
Stream.Clear()
}
func GetHTTPRouteOrExact(alias, host string) (HTTPRoute, bool) {
r, ok := HTTP.Get(alias)
if ok {
return r, true
}
// try find with exact match
return HTTP.Get(host)
}
func Get(alias string) (Route, bool) {
r, ok := HTTP.Get(alias)
if ok {
return r, true
}
return Stream.Get(alias)
}