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