mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-18 23:33:51 +01:00
added load balance support and verbose level
This commit is contained in:
30
src/go-proxy/path_pool_map.go
Normal file
30
src/go-proxy/path_pool_map.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type pathPoolMap struct {
|
||||
*SafeMap[string, *httpLoadBalancePool]
|
||||
}
|
||||
|
||||
func newPathPoolMap() pathPoolMap {
|
||||
return pathPoolMap{
|
||||
NewSafeMap[string](NewHTTPLoadBalancePool),
|
||||
}
|
||||
}
|
||||
|
||||
func (m pathPoolMap) Add(path string, route *HTTPRoute) {
|
||||
m.Ensure(path)
|
||||
m.Get(path).Add(route)
|
||||
}
|
||||
|
||||
func (m pathPoolMap) FindMatch(pathGot string) (*HTTPRoute, error) {
|
||||
for pathWant, v := range m.m {
|
||||
if strings.HasPrefix(pathGot, pathWant) {
|
||||
return v.Pick(), nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("no matching route for path %s", pathGot)
|
||||
}
|
||||
Reference in New Issue
Block a user