github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/bss/v2/resources/requests.go (about) 1 package resources 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 ) 6 7 var requestOpts = golangsdk.RequestOpts{ 8 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 9 } 10 11 // ListOpts allows to filter list data using given parameters. 12 type ListOpts struct { 13 // List of resource IDs. 14 ResourceIds []string `json:"resource_ids,omitempty"` 15 // Order ID. 16 OrderId string `json:"order_id,omitempty"` 17 // Whether to query only the main resource, this parameter is invalid when the request parameter is the ID of the 18 // sub-resource. If the resource_ids is the ID of the sub-resource, it can only query itself. 19 OnlyMainResource int `json:"only_main_resource,omitempty"` 20 // resource status. 21 StatusList []int `json:"status_list,omitempty"` 22 // Query the list of resources that have expired within the specified time period, the start time of the time 23 // period, and the UTC time. 24 ExpireTimeBegin string `json:"expire_time_begin,omitempty"` 25 // Query the list of resources that have expired within the specified time period, the end time of the time period, 26 // and the UTC time. 27 ExpireTimeEnd string `json:"expire_time_end,omitempty"` 28 } 29 30 func List(c *golangsdk.ServiceClient, opts ListOpts) (*QueryResp, error) { 31 b, err := golangsdk.BuildRequestBody(opts, "") 32 if err != nil { 33 return nil, err 34 } 35 36 var r QueryResp 37 _, err = c.Post(queryURL(c), b, &r, &golangsdk.RequestOpts{ 38 MoreHeaders: requestOpts.MoreHeaders, 39 }) 40 if err != nil { 41 return nil, err 42 } 43 return &r, nil 44 } 45 46 // EnableAutoRenew is a method to enable the auto-renew of the prepaid resource. 47 func EnableAutoRenew(c *golangsdk.ServiceClient, resourceId string) error { 48 _, err := c.Post(autoRenewURL(c, resourceId), nil, nil, &golangsdk.RequestOpts{ 49 MoreHeaders: requestOpts.MoreHeaders, 50 OkCodes: []int{204}, 51 }) 52 return err 53 } 54 55 // DisableAutoRenew is a method to disable the auto-renew of the prepaid resource. 56 func DisableAutoRenew(c *golangsdk.ServiceClient, resourceId string) error { 57 _, err := c.Delete(autoRenewURL(c, resourceId), &golangsdk.RequestOpts{ 58 MoreHeaders: requestOpts.MoreHeaders, 59 OkCodes: []int{204}, 60 }) 61 return err 62 }