forked from aiven/aiven-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.go
50 lines (40 loc) · 1.08 KB
/
database.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
package aiven
import "fmt"
type (
Database struct {
Database string `json:"database"`
LcCollate string `json:"lc_collate,omitempty"`
LcType string `json:"lc_type,omitempty"`
}
DatabasesHandler struct {
client *Client
}
CreateDatabaseRequest struct {
Database string `json:"database"`
LcCollate string `json:"lc_collate,omitempty"`
LcType string `json:"lc_type,omitempty"`
}
)
func (h *DatabasesHandler) Create(project, service string, req CreateDatabaseRequest) (*Database, error) {
bts, err := h.client.doPostRequest(fmt.Sprintf("/project/%s/service/%s/db", project, service), req)
if err != nil {
return nil, err
}
rsp, err := handleAPIResponse(bts)
if err != nil {
return nil, err
}
if len(rsp.Errors) != 0 {
return nil, rsp.Errors[0]
}
var db Database
db = Database(req)
return &db, nil
}
func (h *DatabasesHandler) Delete(project, service, database string) error {
bts, err := h.client.doDeleteRequest(fmt.Sprintf("/project/%s/service/%s/db/%s", project, service, database), nil)
if err != nil {
return err
}
return handleDeleteResponse(bts)
}