-
Notifications
You must be signed in to change notification settings - Fork 3
/
model.go
105 lines (84 loc) · 2.4 KB
/
model.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package latest_backups
import (
"encoding/json"
"fmt"
"regexp"
"github.com/RedisLabs/rediscloud-go-api/internal"
"github.com/RedisLabs/rediscloud-go-api/redis"
)
type LatestBackupStatus struct {
CommandType *string `json:"commandType,omitempty"`
Description *string `json:"description,omitempty"`
Status *string `json:"status,omitempty"`
ID *string `json:"taskId,omitempty"`
Response *Response `json:"response,omitempty"`
}
func (o LatestBackupStatus) String() string {
return internal.ToString(o)
}
type Response struct {
ID *int `json:"resourceId,omitempty"`
Resource *json.RawMessage `json:"resource,omitempty"`
Error *Error `json:"error,omitempty"`
}
func (o Response) String() string {
return internal.ToString(o)
}
type Error struct {
Type *string `json:"type,omitempty"`
Description *string `json:"description,omitempty"`
Status *string `json:"status,omitempty"`
}
func (o Error) String() string {
return internal.ToString(o)
}
func (e *Error) StatusCode() string {
matches := errorStatusCode.FindStringSubmatch(redis.StringValue(e.Status))
if len(matches) == 2 {
return matches[1]
}
return ""
}
func (e *Error) Error() string {
return fmt.Sprintf("%s - %s: %s", redis.StringValue(e.Status), redis.StringValue(e.Type), redis.StringValue(e.Description))
}
var errorStatusCode = regexp.MustCompile("^(\\d*).*$")
func NewLatestBackupStatus(task *internal.Task) *LatestBackupStatus {
latestBackupStatus := LatestBackupStatus{
CommandType: task.CommandType,
Description: task.Description,
Status: task.Status,
ID: task.ID,
}
if task.Response != nil {
r := Response{
ID: task.Response.ID,
Resource: task.Response.Resource,
}
if task.Response.Error != nil {
e := Error{
Type: task.Response.Error.Type,
Description: task.Response.Error.Description,
Status: task.Response.Error.Status,
}
r.Error = &e
}
latestBackupStatus.Response = &r
}
return &latestBackupStatus
}
type NotFound struct {
subId int
dbId int
}
func (f *NotFound) Error() string {
return fmt.Sprintf("database %d in subscription %d not found", f.dbId, f.subId)
}
type NotFoundActiveActive struct {
subId int
dbId int
region string
}
func (f *NotFoundActiveActive) Error() string {
return fmt.Sprintf("database %d in subscription %d in region %s not found", f.dbId, f.subId, f.region)
}