@@ -7,6 +7,12 @@ import (
7
7
"github.com/gophercloud/gophercloud/v2/pagination"
8
8
)
9
9
10
+ // ListOptsBuilder allows extensions to add additional parameters to the
11
+ // List request.
12
+ type ListOptsBuilder interface {
13
+ ToSecGroupRuleListQuery () (string , error )
14
+ }
15
+
10
16
// ListOpts allows the filtering and sorting of paginated collections through
11
17
// the API. Filtering is achieved by passing in struct field values that map to
12
18
// the security group rule attributes you want to see returned. SortKey allows
@@ -31,16 +37,25 @@ type ListOpts struct {
31
37
SortDir string `q:"sort_dir"`
32
38
}
33
39
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
+
34
46
// List returns a Pager which allows you to iterate over a collection of
35
47
// security group rules. It accepts a ListOpts struct, which allows you to filter
36
48
// 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
41
57
}
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 {
44
59
return SecGroupRulePage {pagination.LinkedPageBase {PageResult : r }}
45
60
})
46
61
}
0 commit comments