github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/vpc/v1/bandwidths/requests.go (about) 1 package bandwidths 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 func Get(client *golangsdk.ServiceClient, bandwidthId string) (r GetResult) { 9 url := GetURL(client, bandwidthId) 10 _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ 11 OkCodes: []int{200}, 12 }) 13 return 14 } 15 16 type ListOpts struct { 17 // Specifies the resource ID of pagination query. If the parameter 18 // is left blank, only resources on the first page are queried. 19 Marker string `q:"marker"` 20 21 // Specifies the number of records returned on each page. 22 Limit int `q:"limit"` 23 24 // enterprise_project_id 25 // You can use this field to filter the bandwidth under an enterprise project. 26 EnterpriseProjectId string `q:"enterprise_project_id"` 27 } 28 29 type ListOptsBuilder interface { 30 ToListQuery() (string, error) 31 } 32 33 func (opts ListOpts) ToListQuery() (string, error) { 34 q, err := golangsdk.BuildQueryString(opts) 35 return q.String(), err 36 } 37 38 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 39 url := ListURL(client) 40 if opts != nil { 41 query, err := opts.ToListQuery() 42 if err != nil { 43 return pagination.Pager{Err: err} 44 } 45 url += query 46 } 47 48 return pagination.NewPager(client, url, 49 func(r pagination.PageResult) pagination.Page { 50 return BandWidthPage{pagination.LinkedPageBase{PageResult: r}} 51 52 }) 53 } 54 55 type UpdateOpts struct { 56 // Specifies the bandwidth name. The value is a string of 1 to 64 57 // characters that can contain letters, digits, underscores (_), and hyphens (-). 58 Name string `json:"name,omitempty"` 59 60 // Specifies the bandwidth size. The value ranges from 1 Mbit/s to 61 // 300 Mbit/s. 62 Size int `json:"size,omitempty"` 63 } 64 65 type UpdateOptsBuilder interface { 66 ToBandwidthsUpdateMap() (map[string]interface{}, error) 67 } 68 69 func (opts UpdateOpts) ToBandwidthsUpdateMap() (map[string]interface{}, error) { 70 b, err := golangsdk.BuildRequestBody(&opts, "bandwidth") 71 if err != nil { 72 return nil, err 73 } 74 return b, nil 75 } 76 77 func Update(client *golangsdk.ServiceClient, bandwidthId string, opts UpdateOptsBuilder) (r UpdateResult) { 78 b, err := opts.ToBandwidthsUpdateMap() 79 if err != nil { 80 r.Err = err 81 return 82 } 83 84 _, r.Err = client.Put(UpdateURL(client, bandwidthId), b, &r.Body, &golangsdk.RequestOpts{ 85 OkCodes: []int{200}, 86 }) 87 return 88 }