forked from rcarmstrong/go-bamboo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_info.go
70 lines (57 loc) · 1.8 KB
/
server_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
67
68
69
70
package bamboo
import (
"fmt"
"net/http"
)
// InfoService retrieves server information
type InfoService service
// BuildInfo represents the build information of the Bamboo server
type BuildInfo struct {
Version string `json:"version,omitempty"`
Edition string `json:"edition,omitempty"`
BuildDate string `json:"buildDate,omitempty"`
BuildNumber string `json:"buildNumber,omitempty"`
State string `json:"state,omitempty"`
}
// ServerInfo contains information on the Bamboo server
type ServerInfo struct {
State string `json:"state"`
ReindexInProgress bool `json:"reindexInProgress"`
}
func (s *ServerInfo) isRunning() bool {
return s.State == "RUNNING"
}
// BuildInfo fetches the build information of the Bamboo server
func (i *InfoService) BuildInfo() (*BuildInfo, *http.Response, error) {
u := "info.json"
request, err := i.client.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, nil, err
}
buildInfo := &BuildInfo{}
response, err := i.client.Do(request, buildInfo)
if err != nil {
return nil, response, err
}
if !(response.StatusCode == 200) {
return nil, response, &simpleError{fmt.Sprintf("Request for server build info returned %d", response.StatusCode)}
}
return buildInfo, response, nil
}
// ServerInfo fetches the Bamboo server information
func (i *InfoService) ServerInfo() (*ServerInfo, *http.Response, error) {
u := "server.json"
request, err := i.client.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, nil, err
}
serverInfo := &ServerInfo{}
response, err := i.client.Do(request, serverInfo)
if err != nil {
return nil, response, err
}
if !(response.StatusCode == 200) {
return nil, response, &simpleError{fmt.Sprintf("Request for server info returned %d", response.StatusCode)}
}
return serverInfo, response, nil
}