-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcctray.go
35 lines (27 loc) · 806 Bytes
/
cctray.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
package gocd
import (
"encoding/xml"
"net/http"
"github.com/jinzhu/copier"
"github.com/nikhilsbhat/gocd-sdk-go/pkg/errors"
)
func (conf *client) GetCCTray() ([]Project, error) {
newClient := &client{}
if err := copier.CopyWithOption(newClient, conf, copier.Option{IgnoreEmpty: true, DeepCopy: true}); err != nil {
return nil, err
}
var projectsConf Projects
resp, err := newClient.httpClient.R().
Get("cctray.xml")
if err != nil {
return nil, &errors.APIError{Err: err, Message: "get cctray"}
}
if resp.StatusCode() != http.StatusOK {
return nil, &errors.NonOkError{Code: resp.StatusCode(), Response: resp}
}
//nolint:musttag
if err = xml.Unmarshal(resp.Body(), &projectsConf); err != nil {
return nil, &errors.MarshalError{Err: err}
}
return projectsConf.Project, nil
}