-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinfo.go
66 lines (58 loc) · 1.34 KB
/
info.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
54
55
56
57
58
59
60
61
62
63
64
65
66
package godd
import (
"encoding/json"
"io/ioutil"
"net"
"net/http"
"time"
)
var httpTransport = &http.Transport{
Dial: (&net.Dialer{
Timeout: 60 * time.Second,
}).Dial,
TLSHandshakeTimeout: 60 * time.Second,
}
var httpClient = &http.Client{
Timeout: time.Second * 60,
Transport: httpTransport,
}
// Info structure contain informations fetched by the
// GetInfo function
type Info struct {
Status struct {
Code int `json:"code"`
Msg string `json:"msg"`
} `json:"status"`
Head struct {
Method string `json:"method"`
Version string `json:"version"`
Branch string `json:"branch"`
Commit string `json:"commit"`
Services []struct {
Mltype string `json:"mltype"`
Name string `json:"name"`
Description string `json:"description"`
Mllib string `json:"mllib"`
Predict bool `json:"predict"`
} `json:"services"`
} `json:"head"`
}
// GetInfo return an object containing informations from /info
func GetInfo(host string) (info *Info, err error) {
// Perform GET request on /info
resp, err := http.Get(host + "/info")
if err != nil {
return info, err
}
// Read response
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return info, err
}
// Fill info structure with response data
err = json.Unmarshal(body, &info)
if err != nil {
return info, err
}
return info, nil
}