-
Notifications
You must be signed in to change notification settings - Fork 73
/
client_windows.go
50 lines (42 loc) · 1.26 KB
/
client_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//go:build windows
// +build windows
package workloadapi
import (
"errors"
"path/filepath"
"github.com/Microsoft/go-winio"
"google.golang.org/grpc"
)
// appendDialOptionsOS appends OS specific dial options
func (c *Client) appendDialOptionsOS() {
if c.config.namedPipeName != "" {
// Use the dialer to connect to named pipes only if a named pipe
// is defined (i.e. WithNamedPipeName is used).
c.config.dialOptions = append(c.config.dialOptions, grpc.WithContextDialer(winio.DialPipeContext))
}
}
func (c *Client) setAddress() error {
var err error
if c.config.namedPipeName != "" {
if c.config.address != "" {
return errors.New("only one of WithAddr or WithNamedPipeName options can be used, not both")
}
c.config.address = namedPipeTarget(c.config.namedPipeName)
return nil
}
if c.config.address == "" {
var ok bool
c.config.address, ok = GetDefaultAddress()
if !ok {
return errors.New("workload endpoint socket address is not configured")
}
}
c.config.address, err = parseTargetFromAddr(c.config.address)
return err
}
// namedPipeTarget returns a target string suitable for
// dialing the endpoint address based on the provided
// pipe name.
func namedPipeTarget(pipeName string) string {
return `\\.\` + filepath.Join("pipe", pipeName)
}