mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00

- 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.
49 lines
780 B
Go
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)
|
|
}
|