Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8f342a3

Browse filesBrowse files
committed
networks: Security groups rules List to accept a Builder
1 parent 2a1c755 commit 8f342a3
Copy full SHA for 8f342a3

File tree

1 file changed

+21
-6
lines changed
Filter options
  • openstack/networking/v2/extensions/security/rules

1 file changed

+21
-6
lines changed

‎openstack/networking/v2/extensions/security/rules/requests.go

Copy file name to clipboardExpand all lines: openstack/networking/v2/extensions/security/rules/requests.go
+21-6Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import (
77
"github.com/gophercloud/gophercloud/v2/pagination"
88
)
99

10+
// ListOptsBuilder allows extensions to add additional parameters to the
11+
// List request.
12+
type ListOptsBuilder interface {
13+
ToSecGroupRuleListQuery() (string, error)
14+
}
15+
1016
// ListOpts allows the filtering and sorting of paginated collections through
1117
// the API. Filtering is achieved by passing in struct field values that map to
1218
// the security group rule attributes you want to see returned. SortKey allows
@@ -31,16 +37,25 @@ type ListOpts struct {
3137
SortDir string `q:"sort_dir"`
3238
}
3339

40+
// ToPortListQuery formats a ListOpts into a query string.
41+
func (opts ListOpts) ToSecGroupRuleListQuery() (string, error) {
42+
q, err := gophercloud.BuildQueryString(opts)
43+
return q.String(), err
44+
}
45+
3446
// List returns a Pager which allows you to iterate over a collection of
3547
// security group rules. It accepts a ListOpts struct, which allows you to filter
3648
// and sort the returned collection for greater efficiency.
37-
func List(c *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
38-
q, err := gophercloud.BuildQueryString(&opts)
39-
if err != nil {
40-
return pagination.Pager{Err: err}
49+
func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
50+
url := rootURL(c)
51+
if opts != nil {
52+
query, err := opts.ToSecGroupRuleListQuery()
53+
if err != nil {
54+
return pagination.Pager{Err: err}
55+
}
56+
url += query
4157
}
42-
u := rootURL(c) + q.String()
43-
return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
58+
return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
4459
return SecGroupRulePage{pagination.LinkedPageBase{PageResult: r}}
4560
})
4661
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.