-
Notifications
You must be signed in to change notification settings - Fork 28
/
service_tags.go
53 lines (43 loc) · 1.38 KB
/
service_tags.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
package aiven
import "context"
type (
// ServiceTagsHandler is the client which interacts with the Aiven service tags endpoints.
ServiceTagsHandler struct {
client *Client
}
// ServiceTagsRequest contains the parameters used to set service tags.
ServiceTagsRequest struct {
Tags map[string]string `json:"tags"`
}
// ServiceTagsResponse represents the response from Aiven for listing service tags.
ServiceTagsResponse struct {
APIResponse
Tags map[string]string `json:"tags"`
}
)
// Set sets service tags with the given parameters.
func (h *ServiceTagsHandler) Set(ctx context.Context, project, service string, req ServiceTagsRequest) (*ServiceTagsResponse, error) {
path := buildPath("project", project, "service", service, "tags")
bts, err := h.client.doPutRequest(ctx, path, req)
if err != nil {
return nil, err
}
var rsp ServiceTagsResponse
if errR := checkAPIResponse(bts, &rsp); errR != nil {
return nil, errR
}
return &rsp, nil
}
// Get returns a list of all service tags.
func (h *ServiceTagsHandler) Get(ctx context.Context, project, service string) (*ServiceTagsResponse, error) {
path := buildPath("project", project, "service", service, "tags")
bts, err := h.client.doGetRequest(ctx, path, nil)
if err != nil {
return nil, err
}
var rsp ServiceTagsResponse
if errR := checkAPIResponse(bts, &rsp); errR != nil {
return nil, errR
}
return &rsp, nil
}