github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/lts/huawei/loggroups/requests.go (about) 1 package loggroups 2 3 import "github.com/huaweicloud/golangsdk" 4 5 // CreateOptsBuilder is used for creating log group parameters. 6 type CreateOptsBuilder interface { 7 ToLogGroupsCreateMap() (map[string]interface{}, error) 8 } 9 10 // CreateOpts is a struct that contains all the parameters. 11 type CreateOpts struct { 12 // Specifies the log group name. 13 LogGroupName string `json:"log_group_name" required:"true"` 14 15 // Specifies the log expiration time. 16 TTL int `json:"ttl_in_days,omitempty"` 17 } 18 19 // ToLogGroupsCreateMap is used for type convert 20 func (ops CreateOpts) ToLogGroupsCreateMap() (map[string]interface{}, error) { 21 return golangsdk.BuildRequestBody(ops, "") 22 } 23 24 // Create a log group with given parameters. 25 func Create(client *golangsdk.ServiceClient, ops CreateOptsBuilder) (r CreateResult) { 26 b, err := ops.ToLogGroupsCreateMap() 27 if err != nil { 28 r.Err = err 29 return 30 } 31 32 _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ 33 OkCodes: []int{201}, 34 }) 35 36 return 37 } 38 39 // UpdateOptsBuilder allows extensions to add additional parameters to the 40 // Update request. 41 type UpdateOptsBuilder interface { 42 ToLogGroupsUpdateMap() (map[string]interface{}, error) 43 } 44 45 // UpdateOpts contain options for updating an existing Group. 46 // For more information about the parameters, see the LogGroup object. 47 type UpdateOpts struct { 48 // Specifies the log expiration time. 49 TTL int `json:"ttl_in_days,omitempty"` 50 } 51 52 // ToLogGroupsUpdateMap is used for type convert 53 func (ops UpdateOpts) ToLogGroupsUpdateMap() (map[string]interface{}, error) { 54 return golangsdk.BuildRequestBody(ops, "") 55 } 56 57 // update a log group with given parameters by id. 58 func Update(client *golangsdk.ServiceClient, ops UpdateOptsBuilder, id string) (r UpdateResult) { 59 b, err := ops.ToLogGroupsUpdateMap() 60 if err != nil { 61 r.Err = err 62 return 63 } 64 65 _, r.Err = client.Post(updateURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ 66 OkCodes: []int{200}, 67 }) 68 69 return 70 } 71 72 // Delete a log group by id 73 func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { 74 opts := golangsdk.RequestOpts{ 75 MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"}, 76 } 77 _, r.Err = client.Delete(deleteURL(client, id), &opts) 78 return 79 } 80 81 // Get log group list 82 func List(client *golangsdk.ServiceClient) (r ListResults) { 83 opts := golangsdk.RequestOpts{ 84 MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"}, 85 } 86 _, r.Err = client.Get(listURL(client), &r.Body, &opts) 87 return 88 }