forked from aiven/aiven-go-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
service_task_acc.go
63 lines (53 loc) · 1.67 KB
/
service_task_acc.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
package aiven
type (
// ServiceTaskHandler Aiven go-client handler for Service tesks
ServiceTaskHandler struct {
client *Client
}
// ServiceTaskResponse represents service task response
ServiceTaskResponse struct {
APIResponse
Task ServiceTask `json:"task"`
}
// ServiceTask represents a service task
ServiceTask struct {
CreateTime string `json:"create_time"`
Result string `json:"result"`
TaskType string `json:"task_type"`
Success *bool `json:"success"`
SourcePgVersion string `json:"source_pg_version,omitempty"`
TargetPgVersion string `json:"target_pg_version,omitempty"`
Id string `json:"task_id,omitempty"`
}
// ServiceTaskRequest represents service task request
ServiceTaskRequest struct {
TargetVersion string `json:"target_version"`
TaskType string `json:"task_type"`
}
)
// Create creates a bew service task
func (h ServiceTaskHandler) Create(project, service string, r ServiceTaskRequest) (*ServiceTaskResponse, error) {
path := buildPath("project", project, "service", service, "task")
bts, err := h.client.doPostRequest(path, r)
if err != nil {
return nil, err
}
var rsp ServiceTaskResponse
if errR := checkAPIResponse(bts, &rsp); errR != nil {
return nil, errR
}
return &rsp, nil
}
// Get retrieves a new service task
func (h ServiceTaskHandler) Get(project, service, id string) (*ServiceTaskResponse, error) {
path := buildPath("project", project, "service", service, "task", id)
bts, err := h.client.doGetRequest(path, nil)
if err != nil {
return nil, err
}
var rsp ServiceTaskResponse
if errR := checkAPIResponse(bts, &rsp); errR != nil {
return nil, errR
}
return &rsp, nil
}