github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/elb/v3/logtanks/requests.go (about) 1 package logtanks 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 ) 6 7 // CreateOptsBuilder allows extensions to add additional parameters to the 8 // Create request. 9 type CreateOptsBuilder interface { 10 ToLogTanksCreateMap() (map[string]interface{}, error) 11 } 12 13 // CreateOpts is the common options struct used in this package's Create 14 // operation. 15 type CreateOpts struct { 16 // The LoadBalancer on which the log will be associated with. 17 LoadbalancerID string `json:"loadbalancer_id" required:"true"` 18 19 // The log group on which the log will be associated with. 20 LogGroupId string `json:"log_group_id" required:"true"` 21 22 // The topic on which the log will subscribe. 23 LogTopicId string `json:"log_topic_id" required:"true"` 24 } 25 26 // ToLogTanksCreateMap builds a request body from CreateOpts. 27 func (opts CreateOpts) ToLogTanksCreateMap() (map[string]interface{}, error) { 28 return golangsdk.BuildRequestBody(opts, "logtank") 29 } 30 31 // Create is an operation which provisions a new Logtanks based on the 32 // configuration defined in the CreateOpts struct. Once the request is 33 // validated and progress has started on the provisioning process, a 34 // CreateResult will be returned. 35 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 36 b, err := opts.ToLogTanksCreateMap() 37 if err != nil { 38 r.Err = err 39 return 40 } 41 _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) 42 return 43 } 44 45 // Get retrieves a particular Logtanks based on its unique ID. 46 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 47 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 48 return 49 } 50 51 // UpdateOptsBuilder allows extensions to add additional parameters to the 52 // Update request. 53 type UpdateOptsBuilder interface { 54 ToLogTanksUpdateMap() (map[string]interface{}, error) 55 } 56 57 // UpdateOpts is the common options struct used in this package's Update 58 // operation. 59 type UpdateOpts struct { 60 // The log group on which the log will be associated with. 61 LogGroupId string `json:"log_group_id,omitempty"` 62 63 // The topic on which the log will subscribe. 64 LogTopicId string `json:"log_topic_id,omitempty"` 65 } 66 67 // ToLogTanksUpdateMap builds a request body from UpdateOpts. 68 func (opts UpdateOpts) ToLogTanksUpdateMap() (map[string]interface{}, error) { 69 return golangsdk.BuildRequestBody(opts, "logtank") 70 } 71 72 // Update is an operation which modifies the attributes of the specified 73 // Logtank. 74 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { 75 b, err := opts.ToLogTanksUpdateMap() 76 if err != nil { 77 r.Err = err 78 return 79 } 80 _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ 81 OkCodes: []int{200}, 82 }) 83 return 84 } 85 86 // Delete will permanently delete a particular Logtank based on its 87 // unique ID. 88 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 89 _, r.Err = c.Delete(resourceURL(c, id), nil) 90 return 91 }