mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-18 23:33:51 +01:00
31 lines
577 B
Go
31 lines
577 B
Go
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.Iterator() {
|
|
if strings.HasPrefix(pathGot, pathWant) {
|
|
return v.Pick(), nil
|
|
}
|
|
}
|
|
return nil, fmt.Errorf("no matching route for path %s", pathGot)
|
|
}
|