github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/iec/v1/bandwidths/requests.go (about) 1 package bandwidths 2 3 import ( 4 "net/http" 5 6 "github.com/huaweicloud/golangsdk" 7 ) 8 9 func Get(client *golangsdk.ServiceClient, bandwidthId string) (r GetResult) { 10 url := GetURL(client, bandwidthId) 11 _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ 12 OkCodes: []int{http.StatusOK}, 13 }) 14 return 15 } 16 17 type UpdateOpts struct { 18 // Specifies the bandwidth name. The value is a string of 1 to 64 19 // characters that can contain letters, digits, underscores (_), and hyphens (-). 20 Name string `json:"name,omitempty"` 21 22 // Specifies the bandwidth size. The value ranges from 1 Mbit/s to 23 // 300 Mbit/s. 24 Size int `json:"size,omitempty"` 25 } 26 27 type UpdateOptsBuilder interface { 28 ToBandwidthsUpdateMap() (map[string]interface{}, error) 29 } 30 31 func (opts UpdateOpts) ToBandwidthsUpdateMap() (map[string]interface{}, error) { 32 b, err := golangsdk.BuildRequestBody(&opts, "bandwidth") 33 if err != nil { 34 return nil, err 35 } 36 return b, nil 37 } 38 39 func Update(client *golangsdk.ServiceClient, bandwidthId string, opts UpdateOptsBuilder) (r UpdateResult) { 40 b, err := opts.ToBandwidthsUpdateMap() 41 if err != nil { 42 r.Err = err 43 return 44 } 45 46 _, r.Err = client.Put(UpdateURL(client, bandwidthId), b, &r.Body, &golangsdk.RequestOpts{ 47 OkCodes: []int{http.StatusOK}, 48 }) 49 return 50 }