-
Notifications
You must be signed in to change notification settings - Fork 3
/
dind.go
41 lines (35 loc) · 830 Bytes
/
dind.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
package hosts
import (
"fmt"
"net"
"strconv"
)
const (
DINDPort = "2375"
)
type dindDialer struct {
Address string
Port string
Network string
}
func DindConnFactory(h *Host) (func(network, address string) (net.Conn, error), error) {
newDindDialer := &dindDialer{
Address: h.Address,
Port: DINDPort,
}
return newDindDialer.Dial, nil
}
func DindHealthcheckConnFactory(h *Host) (func(network, address string) (net.Conn, error), error) {
newDindDialer := &dindDialer{
Address: h.Address,
Port: strconv.Itoa(h.LocalConnPort),
}
return newDindDialer.Dial, nil
}
func (d *dindDialer) Dial(network, addr string) (net.Conn, error) {
conn, err := net.Dial(network, d.Address+":"+d.Port)
if err != nil {
return nil, fmt.Errorf("Failed to dial dind address [%s]: %v", addr, err)
}
return conn, err
}