-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.go
64 lines (56 loc) · 1.45 KB
/
service.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
package bamboo
const (
BAMBOO_SERVICE_API_URI = "api/services"
)
type Service struct {
Id string `json:"id"`
Acl string `json:"acl"`
}
func NewService(id, acl string) *Service {
return &Service{
Id: id,
Acl: acl,
}
}
func (client *Client) HasService(name string) (bool, error) {
allServices, err := client.AllServices()
if err != nil {
return false, err
}
for k, v := range allServices {
if k == name {
if v.Id == name {
return true, nil
}
}
}
return false, nil
}
func (client *Client) AllServices() (map[string]*Service, error) {
allServices := make(map[string]*Service)
if err := client.apiGet(BAMBOO_SERVICE_API_URI, nil, &allServices); err != nil {
return allServices, err
}
return allServices, nil
}
func (client *Client) CreateService(service *Service) (*Service, error) {
var respService *Service
if err := client.apiPost(BAMBOO_SERVICE_API_URI, service, &respService); err != nil {
return respService, err
}
return respService, nil
}
func (client *Client) UpdateService(service *Service) (*Service, error) {
var respService *Service
if err := client.apiPut(BAMBOO_SERVICE_API_URI+service.Id, service, &respService); err != nil {
return respService, err
}
return nil, nil
}
func (client *Client) DeleteService(name string) (*Service, error) {
var respService *Service
if err := client.apiDelete(BAMBOO_SERVICE_API_URI+name, nil, &respService); err != nil {
return respService, err
}
return respService, nil
}