diff --git a/dial.go b/dial.go index 562cf39..affc034 100644 --- a/dial.go +++ b/dial.go @@ -3,6 +3,7 @@ package tdx import ( "context" "github.com/injoyai/ios" + "github.com/injoyai/logs" "math/rand" "net" "strings" @@ -43,3 +44,25 @@ func NewRandomDial(hosts []string) ios.DialFunc { return c, addr, err } } + +func NewRangeDial(hosts []string) ios.DialFunc { + if len(hosts) == 0 { + hosts = Hosts + } + return func(ctx context.Context) (c ios.ReadWriteCloser, _ string, err error) { + for i, addr := range hosts { + if !strings.Contains(addr, ":") { + addr += ":7709" + } + c, err = net.Dial("tcp", addr) + if err == nil { + return c, addr, nil + } + if i < len(hosts)-1 { + //最后一个错误返回出去 + logs.Err(err) + } + } + return + } +}