Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 604f24a

Browse files
committed
Applying comments 1, 2, 3 (PR #448)
1 parent 484e062 commit 604f24a

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

openstack/telemetry/v2/meters/requests.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package meters
22

33
import (
44
"fmt"
5+
"net/http"
56

67
"github.com/rackspace/gophercloud"
78
)
@@ -28,20 +29,21 @@ func (opts ListOpts) ToMeterListQuery() (string, error) {
2829
}
2930

3031
// List makes a request against the API to list meters accessible to you.
31-
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) (res listResult, err error) {
32+
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) listResult {
33+
var res listResult
3234
url := listURL(client)
3335

3436
if opts != nil {
3537
query, err := opts.ToMeterListQuery()
3638
if err != nil {
37-
return res, err
39+
res.Err = err
40+
return res
3841
}
3942
url += query
4043
}
4144

42-
_, err = client.Get(url, &res.Body, &gophercloud.RequestOpts{})
43-
44-
return
45+
_, res.Err = client.Get(url, &res.Body, &gophercloud.RequestOpts{})
46+
return res
4547
}
4648

4749
// StatisticsOptsBuilder allows extensions to add additional parameters to the
@@ -75,19 +77,21 @@ func (opts MeterStatisticsOpts) ToMeterStatisticsQuery() (string, error) {
7577
}
7678

7779
// List makes a request against the API to list meters accessible to you.
78-
func MeterStatistics(client *gophercloud.ServiceClient, n string, opts MeterStatisticsOptsBuilder) (res statisticsResult, err error) {
80+
func MeterStatistics(client *gophercloud.ServiceClient, n string, opts MeterStatisticsOptsBuilder) statisticsResult {
81+
var res statisticsResult
7982
url := statisticsURL(client, n)
8083

8184
if opts != nil {
8285
query, err := opts.ToMeterStatisticsQuery()
8386
if err != nil {
84-
return res, err
87+
res.Err = err
88+
return res
8589
}
8690
url += query
8791
}
8892

89-
b, err := client.Get(url, &res.Body, &gophercloud.RequestOpts{})
93+
var b *http.Response
94+
b, res.Err = client.Get(url, &res.Body, &gophercloud.RequestOpts{})
9095
fmt.Printf("%+v\n%+v\n", res, b)
91-
92-
return
96+
return res
9397
}

openstack/telemetry/v2/meters/requests_test.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,27 @@ func TestListMeters(t *testing.T) {
1212
defer th.TeardownHTTP()
1313
HandleMeterListSuccessfully(t)
1414

15-
res, err := List(client.ServiceClient(), ListOpts{})
16-
th.AssertNoErr(t, err)
17-
list, err := res.Extract()
15+
list, err := List(client.ServiceClient(), ListOpts{}).Extract()
1816
th.AssertNoErr(t, err)
1917

20-
if len(*list) != 2 {
21-
t.Fatalf("Expected 2 meters, got %d", len(*list))
18+
if len(list) != 2 {
19+
t.Fatalf("Expected 2 meters, got %d", len(list))
2220
}
23-
th.CheckDeepEquals(t, MeterHerp, (*list)[0])
24-
th.CheckDeepEquals(t, MeterDerp, (*list)[1])
21+
th.CheckDeepEquals(t, MeterHerp, (list)[0])
22+
th.CheckDeepEquals(t, MeterDerp, (list)[1])
2523
}
2624

2725
func TestMeterStatistics(t *testing.T) {
2826
th.SetupHTTP()
2927
defer th.TeardownHTTP()
3028
HandleMeterStatisticsSuccessfully(t)
3129

32-
res, err := MeterStatistics(client.ServiceClient(), "memory", MeterStatisticsOpts{})
33-
th.AssertNoErr(t, err)
34-
list, err := res.Extract()
30+
list, err := MeterStatistics(client.ServiceClient(), "memory", MeterStatisticsOpts{}).Extract()
3531
th.AssertNoErr(t, err)
3632

37-
if len(*list) != 2 {
38-
t.Fatalf("Expected 2 statistics, got %d", len(*list))
33+
if len(list) != 2 {
34+
t.Fatalf("Expected 2 statistics, got %d", len(list))
3935
}
40-
th.CheckDeepEquals(t, StatisticsHerp, (*list)[0])
41-
th.CheckDeepEquals(t, StatisticsDerp, (*list)[1])
36+
th.CheckDeepEquals(t, StatisticsHerp, (list)[0])
37+
th.CheckDeepEquals(t, StatisticsDerp, (list)[1])
4238
}

openstack/telemetry/v2/meters/results.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type listResult struct {
2323
}
2424

2525
// Extract interprets any listResult as an array of MeterListResult
26-
func (r listResult) Extract() (*[]MeterListResult, error) {
26+
func (r listResult) Extract() ([]MeterListResult, error) {
2727
if r.Err != nil {
2828
return nil, r.Err
2929
}
@@ -44,7 +44,7 @@ func (r listResult) Extract() (*[]MeterListResult, error) {
4444
return nil, err
4545
}
4646

47-
return &response, nil
47+
return response, nil
4848
}
4949

5050
type MeterStatisticsResult struct {
@@ -67,7 +67,7 @@ type statisticsResult struct {
6767
}
6868

6969
// Extract interprets any serverResult as a Server, if possible.
70-
func (r statisticsResult) Extract() (*[]MeterStatisticsResult, error) {
70+
func (r statisticsResult) Extract() ([]MeterStatisticsResult, error) {
7171
if r.Err != nil {
7272
return nil, r.Err
7373
}
@@ -88,7 +88,7 @@ func (r statisticsResult) Extract() (*[]MeterStatisticsResult, error) {
8888
return nil, err
8989
}
9090

91-
return &response, nil
91+
return response, nil
9292
}
9393

9494
func toMapFromString(from reflect.Kind, to reflect.Kind, data interface{}) (interface{}, error) {

0 commit comments

Comments
 (0)