update config parsing

This commit is contained in:
ginuerzh
2022-02-07 22:15:16 +08:00
parent 0983ecc52f
commit 1ec10ff7dd
23 changed files with 846 additions and 534 deletions

View File

@ -1,5 +1,9 @@
package chain
type Chainer interface {
Route(network, address string) *Route
}
type Chain struct {
groups []*NodeGroup
}
@ -8,16 +12,12 @@ func (c *Chain) AddNodeGroup(group *NodeGroup) {
c.groups = append(c.groups, group)
}
func (c *Chain) GetRoute() (r *route) {
return c.GetRouteFor("tcp", "")
}
func (c *Chain) GetRouteFor(network, address string) (r *route) {
func (c *Chain) Route(network, address string) (r *Route) {
if c == nil || len(c.groups) == 0 {
return
}
r = &route{}
r = &Route{}
for _, group := range c.groups {
node := group.Next()
if node == nil {
@ -32,14 +32,10 @@ func (c *Chain) GetRouteFor(network, address string) (r *route) {
WithRoute(r)
node = node.Copy()
node.Transport = tr
r = &route{}
r = &Route{}
}
r.AddNode(node)
r.addNode(node)
}
return r
}
func (c *Chain) IsEmpty() bool {
return c == nil || len(c.groups) == 0
}