diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 9fd3307..19ea494 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -18,6 +18,4 @@ jobs: - uses: actions/checkout@v2 - name: test - run: go test ./... - - name: race - run: go test -race ./... \ No newline at end of file + run: go test -race -v ./... \ No newline at end of file diff --git a/go.mod b/go.mod index e3f3ea3..1830630 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/FileGo/octopusenergyapi -go 1.15 +go 1.16 require ( github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index ba78b5d..358cd79 100644 --- a/go.sum +++ b/go.sum @@ -10,7 +10,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= diff --git a/octopusapi.go b/octopusapi.go index cc5f73d..90ad06b 100644 --- a/octopusapi.go +++ b/octopusapi.go @@ -179,7 +179,7 @@ func (c *Client) listProductsPage(URL string) ([]Product, string, error) { return nil, "", errors.Errorf("error retrieving: %v", err) } - return data.Results, data.Next, nil + return data.Results, strings.TrimPrefix(data.Next, baseURL), nil } // ListProducts returns a list of energy products @@ -187,7 +187,7 @@ func (c *Client) listProductsPage(URL string) ([]Product, string, error) { func (c *Client) ListProducts() ([]Product, error) { var products []Product - URL := fmt.Sprintf("%s/products/", c.URL) + URL := "/products/" for { pageProducts, url, err := c.listProductsPage(URL) @@ -196,10 +196,7 @@ func (c *Client) ListProducts() ([]Product, error) { return nil, errors.Errorf("error retrieving products page: %v", err) } - for _, product := range pageProducts { - products = append(products, product) - } - + products = append(products, pageProducts...) if URL == "" { break } diff --git a/structs.go b/structs.go index 9bf9aaa..0166688 100644 --- a/structs.go +++ b/structs.go @@ -2,7 +2,6 @@ package octopusenergyapi import ( "net/http" - "regexp" "time" ) @@ -58,9 +57,8 @@ type GridSupplyPoint struct { // Client represents a Client to be used with the API type Client struct { - httpClient *http.Client - URL string - postcodeRegex *regexp.Regexp + httpClient *http.Client + URL string } // MeterPoint represents a meter point