multinet/default.go
Dmitrii Stepanov ee601a7b5f [#3] dialer: Add default dialer.
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-11-02 13:25:54 +03:00

31 lines
634 B
Go

package multinet
import (
"context"
"fmt"
"net"
)
var (
defaultDialer Multidialer
defaultDialerErr error
)
func init() {
var err error
defaultDialer, err = NewDialer(Config{
Balancer: BalancerTypeRoundRobin,
Subnets: []string{"0.0.0.0/0", "::/0"},
})
if err != nil {
defaultDialerErr = fmt.Errorf("failed to initialize default dialier: %w", err)
}
}
// Dial dials provided network and address using default dialer.
func Dial(network, address string) (net.Conn, error) {
if defaultDialerErr != nil {
return nil, defaultDialerErr
}
return defaultDialer.DialContext(context.Background(), network, address)
}