forked from TrueCloudLab/multinet
31 lines
634 B
Go
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)
|
|
}
|