2018-04-19 13:07:27 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2020-11-17 08:19:27 -05:00
|
|
|
"context"
|
2018-04-19 13:07:27 -04:00
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
|
2020-04-16 11:06:33 -04:00
|
|
|
winio "github.com/Microsoft/go-winio"
|
2018-04-19 13:07:27 -04:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2020-11-17 08:19:27 -05:00
|
|
|
func dialer(ctx context.Context, address string) (net.Conn, error) {
|
2018-04-19 13:07:27 -04:00
|
|
|
addrParts := strings.SplitN(address, "://", 2)
|
|
|
|
if len(addrParts) != 2 {
|
|
|
|
return nil, errors.Errorf("invalid address %s", address)
|
|
|
|
}
|
|
|
|
switch addrParts[0] {
|
|
|
|
case "npipe":
|
2019-04-03 02:23:23 -04:00
|
|
|
address = strings.Replace(addrParts[1], "/", "\\", -1)
|
2020-11-17 08:19:27 -05:00
|
|
|
return winio.DialPipeContext(ctx, address)
|
2018-04-19 13:07:27 -04:00
|
|
|
default:
|
2020-11-17 08:19:27 -05:00
|
|
|
var d net.Dialer
|
|
|
|
return d.DialContext(ctx, addrParts[0], addrParts[1])
|
2018-04-19 13:07:27 -04:00
|
|
|
}
|
|
|
|
}
|