2017-07-12 05:08:53 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2020-07-18 21:52:29 +00:00
|
|
|
"context"
|
2017-07-12 05:08:53 +00:00
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
|
2020-02-25 00:26:04 +00:00
|
|
|
winio "github.com/Microsoft/go-winio"
|
2018-05-14 13:55:56 +00:00
|
|
|
"github.com/pkg/errors"
|
2017-07-12 05:08:53 +00:00
|
|
|
)
|
|
|
|
|
2020-07-18 21:52:29 +00:00
|
|
|
func dialer(ctx context.Context, address string) (net.Conn, error) {
|
2018-05-14 13:55:56 +00:00
|
|
|
addrParts := strings.SplitN(address, "://", 2)
|
|
|
|
if len(addrParts) != 2 {
|
|
|
|
return nil, errors.Errorf("invalid address %s", address)
|
|
|
|
}
|
|
|
|
switch addrParts[0] {
|
|
|
|
case "npipe":
|
2019-03-01 21:34:48 +00:00
|
|
|
address = strings.Replace(addrParts[1], "/", "\\", -1)
|
2020-07-18 21:52:29 +00:00
|
|
|
return winio.DialPipeContext(ctx, address)
|
2018-05-14 13:55:56 +00:00
|
|
|
default:
|
2020-07-18 21:52:29 +00:00
|
|
|
var d net.Dialer
|
|
|
|
return d.DialContext(ctx, addrParts[0], addrParts[1])
|
2018-05-14 13:55:56 +00:00
|
|
|
}
|
2017-07-12 05:08:53 +00:00
|
|
|
}
|