This repository has been archived by the owner on May 8, 2024. It is now read-only.
forked from huaweicloud/huaweicloud-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.go
79 lines (64 loc) · 2 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
package db_user
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
type CreateDbUserOpts struct {
Username string `json:"name" required:"true"`
Password string `json:"password" required:"true"`
}
type CreateDbUserBuilder interface {
ToDbUserCreateMap() (map[string]interface{}, error)
}
func (opts CreateDbUserOpts) ToDbUserCreateMap() (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(&opts, "")
if err != nil {
return nil, err
}
return b, nil
}
func Create(client *gophercloud.ServiceClient, opts CreateDbUserBuilder, instanceId string) (r DbUserResult) {
b, err := opts.ToDbUserCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(createURL(client, instanceId), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{202},
})
return
}
type ListDbUsersOpts struct {
Page int `q:"page" `
Limit int `q:"limit" `
}
type DbUsersBuilder interface {
ToDbUsersListQuery() (string, error)
}
func (opts ListDbUsersOpts) ToDbUsersListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
if err != nil {
return "", err
}
return q.String(), err
}
func List(client *gophercloud.ServiceClient, opts DbUsersBuilder, instance string) pagination.Pager {
url := listURL(client, instance)
if opts != nil {
query, err := opts.ToDbUsersListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
pageRdsList := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return DbUsersPage{pagination.Offset{PageResult: r}}
})
rdsheader := map[string]string{"Content-Type": "application/json"}
pageRdsList.Headers = rdsheader
return pageRdsList
}
func Delete(client *gophercloud.ServiceClient, instanceid string, dbUser string) (r commonResult) {
_, r.Err = client.Delete(deleteURL(client, instanceid, dbUser), &gophercloud.RequestOpts{JSONResponse:&r.Body,OkCodes: []int{202},MoreHeaders: map[string]string{"Content-Type": "application/json"}})
return
}