-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.go
53 lines (45 loc) · 1.07 KB
/
engine.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
51
52
53
package dockerMan
import (
"crypto/tls"
"fmt"
"github.com/yleemj/dockerMan/app/cluster"
"net"
"net/http"
"time"
)
const (
httpTimeout = time.Duration(1 * time.Second)
)
type (
Engine struct {
ID string `json:"id,omitempty" gorethink:"id,omitempty"`
Engine *cluster.Engine `json:"engine,omitempty" gorethink:"engine,omitempty"`
DockerVersion string `json:"docker_version,omitempty"`
}
)
func dialTimeout(network, addr string) (net.Conn, error) {
//fmt.Printf("network: %s, addr: %s\n", network, addr)
return net.DialTimeout(network, addr, httpTimeout)
}
func (e *Engine) Ping() (int, error) {
status := 0
addr := e.Engine.Addr
tlsConfig := &tls.Config{}
transport := http.Transport{
Dial: dialTimeout,
TLSClientConfig: tlsConfig,
}
client := http.Client{
Transport: &transport,
}
//fmt.Printf("client config: %v", *tlsConfig)
uri := fmt.Sprintf("%s/_ping", addr)
resp, err := client.Get(uri)
if err != nil {
return 0, err
} else {
defer resp.Body.Close()
status = resp.StatusCode
}
return status, nil
}