github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v1/bandwidths/requests.go (about) 1 package bandwidths 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 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 ToBWListQuery() (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) ToBWListQuery() (string, error) { 56 q, err := golangsdk.BuildQueryString(opts) 57 return q.String(), err 58 } 59 60 // List is a method by which can get the detailed information of all bandwidths 61 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) (r ListResult) { 62 url := listURL(client) 63 query, err := opts.ToBWListQuery() 64 if err != nil { 65 r.Err = err 66 return 67 } 68 url += query 69 70 _, r.Err = client.Get(url, &r.Body, nil) 71 return 72 }