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
52 lines (43 loc) · 1.52 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
package logstreams
import "github.com/huaweicloud/golangsdk"
// CreateOptsBuilder is used for creating log stream parameters.
type CreateOptsBuilder interface {
ToLogStreamsCreateMap() (map[string]interface{}, error)
}
// CreateOpts is a struct that contains all the parameters.
type CreateOpts struct {
// Specifies the log stream name.
LogStreamName string `json:"log_stream_name" required:"true"`
}
// ToLogStreamsCreateMap is used for type convert
func (ops CreateOpts) ToLogStreamsCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(ops, "")
}
// Create a log stream with given parameters.
func Create(client *golangsdk.ServiceClient, groupId string, ops CreateOptsBuilder) (r CreateResult) {
b, err := ops.ToLogStreamsCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(createURL(client, groupId), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{201},
})
return
}
// Delete a log stream by id
func Delete(client *golangsdk.ServiceClient, groupId string, id string) (r DeleteResult) {
opts := golangsdk.RequestOpts{
MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"},
}
_, r.Err = client.Delete(deleteURL(client, groupId, id), &opts)
return
}
// Get log stream list
func List(client *golangsdk.ServiceClient, groupId string) (r ListResults) {
opts := golangsdk.RequestOpts{
MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"},
}
_, r.Err = client.Get(listURL(client, groupId), &r.Body, &opts)
return
}