-
Notifications
You must be signed in to change notification settings - Fork 2
/
version.go
38 lines (30 loc) · 965 Bytes
/
version.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
package gocd
import (
"encoding/json"
"net/http"
"github.com/jinzhu/copier"
"github.com/nikhilsbhat/gocd-sdk-go/pkg/errors"
)
// GetVersionInfo fetches version information of the GoCD to which it is connected to.
func (conf *client) GetVersionInfo() (VersionInfo, error) {
var version VersionInfo
newClient := &client{}
if err := copier.CopyWithOption(newClient, conf, copier.Option{IgnoreEmpty: true, DeepCopy: true}); err != nil {
return version, err
}
resp, err := newClient.httpClient.R().
SetHeaders(map[string]string{
"Accept": HeaderVersionOne,
}).
Get(VersionEndpoint)
if err != nil {
return version, &errors.APIError{Err: err, Message: "get version information"}
}
if resp.StatusCode() != http.StatusOK {
return version, &errors.NonOkError{Code: resp.StatusCode(), Response: resp}
}
if err = json.Unmarshal(resp.Body(), &version); err != nil {
return version, &errors.MarshalError{Err: err}
}
return version, nil
}