Skip to content

Commit 3eff99b

Browse files
authored
Merge pull request #3348 from gophercloud/bp-v2-91498be
[v2] [networking] add ExtractRoutersInto func helper to routers
2 parents 5650bb1 + e77ceca commit 3eff99b

File tree

1 file changed

+8
-5
lines changed
  • openstack/networking/v2/extensions/layer3/routers

1 file changed

+8
-5
lines changed

openstack/networking/v2/extensions/layer3/routers/results.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,14 @@ func (r RouterPage) IsEmpty() (bool, error) {
122122
// and extracts the elements into a slice of Router structs. In other words,
123123
// a generic collection is mapped into a relevant slice.
124124
func ExtractRouters(r pagination.Page) ([]Router, error) {
125-
var s struct {
126-
Routers []Router `json:"routers"`
127-
}
128-
err := (r.(RouterPage)).ExtractInto(&s)
129-
return s.Routers, err
125+
var s []Router
126+
err := ExtractRoutersInto(r, &s)
127+
return s, err
128+
}
129+
130+
// ExtractRoutersInto extracts the elements into a slice of Router structs.
131+
func ExtractRoutersInto(r pagination.Page, v any) error {
132+
return r.(RouterPage).Result.ExtractIntoSlicePtr(v, "routers")
130133
}
131134

132135
type commonResult struct {

0 commit comments

Comments
 (0)