-
Notifications
You must be signed in to change notification settings - Fork 7
/
results.go
71 lines (60 loc) · 1.64 KB
/
results.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
package domains
import (
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud/pagination"
)
type CreateResult struct {
golangsdk.ErrResult
}
type GetResult struct {
golangsdk.Result
}
type AccessDomain struct {
Organization string `json:"namespace"`
Repository string `json:"repository"`
// Name
AccessDomain string `json:"access_domain"`
Permit string `json:"permit"`
Deadline string `json:"deadline"`
Description string `json:"description"`
CreatorID string `json:"creator_id"`
CreatorName string `json:"creator_name"`
Created string `json:"created"`
Updated string `json:"updated"`
// Status. `true`: valid `false`: expired
Status bool `json:"status"`
}
func (r GetResult) Extract() (*AccessDomain, error) {
// existance check
var existingDomain struct {
Exist bool `json:"exist"`
}
if err := r.ExtractIntoStructPtr(&existingDomain, ""); err != nil {
return nil, err
}
if !existingDomain.Exist {
err404 := golangsdk.ErrDefault404{}
err404.DefaultErrString = "domain does not exist"
return nil, err404
}
// actual extract
domain := new(AccessDomain)
if err := r.ExtractIntoStructPtr(domain, ""); err != nil {
return nil, err
}
return domain, nil
}
type DeleteResult struct {
golangsdk.ErrResult
}
type UpdateResult struct {
golangsdk.ErrResult
}
type AccessDomainPage struct {
pagination.SinglePageBase
}
func ExtractAccessDomains(p pagination.Page) ([]AccessDomain, error) {
var domains []AccessDomain
err := p.(AccessDomainPage).ExtractIntoSlicePtr(&domains, "")
return domains, err
}