mirror of
https://github.com/yusing/godoxy.git
synced 2026-02-22 18:37:46 +01:00
- Introduced `NewTestRoute` function to simplify route creation in benchmark tests. - Replaced direct route validation and starting with error handling using `require.NoError`. - Updated server retrieval to use `common.ProxyHTTPAddr` for consistency. - Improved logging for HTTP route addition errors in `AddRoute` method. * fix(tcp): wrap proxy proto listener before acl * refactor(entrypoint): propagate errors from route registration and stream serving * fix(docs): correct swagger and package README
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package entrypoint
|
|
|
|
import (
|
|
"github.com/yusing/godoxy/internal/common"
|
|
"github.com/yusing/godoxy/internal/types"
|
|
)
|
|
|
|
// httpPoolAdapter implements the PoolLike interface for the HTTP routes.
|
|
type httpPoolAdapter struct {
|
|
ep *Entrypoint
|
|
}
|
|
|
|
func newHTTPPoolAdapter(ep *Entrypoint) httpPoolAdapter {
|
|
return httpPoolAdapter{ep: ep}
|
|
}
|
|
|
|
func (h httpPoolAdapter) Iter(yield func(alias string, route types.HTTPRoute) bool) {
|
|
for addr, srv := range h.ep.servers.Range {
|
|
// default routes are added to both HTTP and HTTPS servers, we don't need to iterate over them twice.
|
|
if addr == common.ProxyHTTPSAddr {
|
|
continue
|
|
}
|
|
for alias, route := range srv.routes.Iter {
|
|
if !yield(alias, route) {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (h httpPoolAdapter) Get(alias string) (types.HTTPRoute, bool) {
|
|
for addr, srv := range h.ep.servers.Range {
|
|
if addr == common.ProxyHTTPSAddr {
|
|
continue
|
|
}
|
|
if route, ok := srv.routes.Get(alias); ok {
|
|
return route, true
|
|
}
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
func (h httpPoolAdapter) Size() (n int) {
|
|
for addr, srv := range h.ep.servers.Range {
|
|
if addr == common.ProxyHTTPSAddr {
|
|
continue
|
|
}
|
|
n += srv.routes.Size()
|
|
}
|
|
return
|
|
}
|