github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v1/bandwidths/requests.go (about) 1 package bandwidths 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 ) 6 7 // UpdateOptsBuilder is an interface by which can be able to build the request 8 // body 9 type UpdateOptsBuilder interface { 10 ToBWUpdateMap() (map[string]interface{}, error) 11 } 12 13 // UpdateOpts is a struct which represents the request body of update method 14 type UpdateOpts struct { 15 Size int `json:"size,omitempty"` 16 Name string `json:"name,omitempty"` 17 } 18 19 func (opts UpdateOpts) ToBWUpdateMap() (map[string]interface{}, error) { 20 return golangsdk.BuildRequestBody(opts, "bandwidth") 21 } 22 23 // Get is a method by which can get the detailed information of a bandwidth 24 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 25 _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) 26 return 27 } 28 29 // Update is a method which can be able to update the port of public ip 30 func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 31 b, err := opts.ToBWUpdateMap() 32 if err != nil { 33 r.Err = err 34 return 35 } 36 _, r.Err = client.Put(resourceURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ 37 OkCodes: []int{200}, 38 }) 39 return 40 } 41 42 // ListOptsBuilder allows extensions to add additional parameters to the 43 // List request. 44 type ListOptsBuilder interface { 45 ToBandwidthListQuery() (string, error) 46 } 47 48 // ListOpts allows extensions to add additional parameters to the API. 49 type ListOpts struct { 50 ShareType string `q:"share_type"` 51 EnterpriseProjectID string `q:"enterprise_project_id"` 52 } 53 54 // ToBWListQuery formats a ListOpts into a query string. 55 func (opts ListOpts) ToBandwidthListQuery() (string, error) { 56 q, err := golangsdk.BuildQueryString(opts) 57 if err != nil { 58 return "", err 59 } 60 return q.String(), err 61 } 62 63 // List is a method by which can get the detailed information of all bandwidths 64 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) (r ListResult) { 65 url := listURL(client) 66 query, err := opts.ToBandwidthListQuery() 67 if err != nil { 68 r.Err = err 69 return 70 } 71 url += query 72 73 _, r.Err = client.Get(url, &r.Body, nil) 74 return 75 }