This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
requests.go
86 lines (75 loc) · 2.62 KB
/
requests.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
package groups
import (
"github.com/huaweicloud/golangsdk"
)
// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToGroupCreateMap() (map[string]interface{}, error)
}
// CreateOpts contains options for creating a API group. This object is passed to
// the API groups Create function.
type CreateOpts struct {
// Name of the API group
Name string `json:"name" required:"true"`
// Description of the API group
Remark string `json:"remark,omitempty"`
}
// ToGroupCreateMap assembles a request body based on the contents of a
// CreateOpts.
func (opts CreateOpts) ToGroupCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "")
}
// Create will create a new API group based on the values in CreateOpts.
func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToGroupCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200, 201},
})
return
}
// UpdateOptsBuilder allows extensions to add additional parameters to the
// Update request.
type UpdateOptsBuilder interface {
ToGroupUpdateMap() (map[string]interface{}, error)
}
// UpdateOpts contain options for updating an existing API group.
type UpdateOpts struct {
// Name of the API group
Name string `json:"name" required:"true"`
// Description of the API group
Remark string `json:"remark,omitempty"`
}
// ToGroupUpdateMap assembles a request body based on the contents of an
// UpdateOpts.
func (opts UpdateOpts) ToGroupUpdateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "")
}
// Update will update the API group with provided information. To extract the updated
// API group from the response, call the Extract method on the UpdateResult.
func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToGroupUpdateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Put(groupURL(client, id), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return
}
// Delete will delete the existing group with the provided ID.
func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
_, r.Err = client.Delete(groupURL(client, id), nil)
return
}
// Get retrieves the group with the provided ID. To extract the Group object
// from the response, call the Extract method on the GetResult.
func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(groupURL(client, id), &r.Body, nil)
return
}