| 1 |
//go:build windows |
| 2 |
|
| 3 |
package npipe |
| 4 |
|
| 5 |
import ( |
| 6 |
"context" |
| 7 |
"net" |
| 8 |
"net/url" |
| 9 |
"strings" |
| 10 |
|
| 11 |
"github.com/Microsoft/go-winio" |
| 12 |
"github.com/moby/buildkit/client/connhelper" |
| 13 |
"github.com/pkg/errors" |
| 14 |
) |
| 15 |
|
| 16 |
// Helper returns helper for connecting to a url via npipes. |
| 17 |
func Helper(u *url.URL) (*connhelper.ConnectionHelper, error) { |
| 18 |
addrParts := strings.SplitN(u.String(), "://", 2) |
| 19 |
if len(addrParts) != 2 { |
| 20 |
return nil, errors.Errorf("invalid address %s", u) |
| 21 |
} |
| 22 |
address := strings.ReplaceAll(addrParts[1], "/", "\\") |
| 23 |
return &connhelper.ConnectionHelper{ |
| 24 |
ContextDialer: func(ctx context.Context, addr string) (net.Conn, error) { |
| 25 |
return winio.DialPipeContext(ctx, address) |
| 26 |
}, |
| 27 |
}, nil |
| 28 |
} |