1// +build go1.13 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// Code generated by Microsoft (R) AutoRest Code Generator. 6// Changes may cause incorrect behavior and will be lost if the code is regenerated. 7 8package armnetwork 9 10import ( 11 "context" 12 "github.com/Azure/azure-sdk-for-go/sdk/armcore" 13 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 14 "net/http" 15 "net/url" 16 "strings" 17) 18 19// UsagesClient contains the methods for the Usages group. 20// Don't use this type directly, use NewUsagesClient() instead. 21type UsagesClient struct { 22 con *armcore.Connection 23 subscriptionID string 24} 25 26// NewUsagesClient creates a new instance of UsagesClient with the specified values. 27func NewUsagesClient(con *armcore.Connection, subscriptionID string) *UsagesClient { 28 return &UsagesClient{con: con, subscriptionID: subscriptionID} 29} 30 31// List - List network usages for a subscription. 32func (client *UsagesClient) List(location string, options *UsagesListOptions) UsagesListResultPager { 33 return &usagesListResultPager{ 34 pipeline: client.con.Pipeline(), 35 requester: func(ctx context.Context) (*azcore.Request, error) { 36 return client.listCreateRequest(ctx, location, options) 37 }, 38 responder: client.listHandleResponse, 39 errorer: client.listHandleError, 40 advancer: func(ctx context.Context, resp UsagesListResultResponse) (*azcore.Request, error) { 41 return azcore.NewRequest(ctx, http.MethodGet, *resp.UsagesListResult.NextLink) 42 }, 43 statusCodes: []int{http.StatusOK}, 44 } 45} 46 47// listCreateRequest creates the List request. 48func (client *UsagesClient) listCreateRequest(ctx context.Context, location string, options *UsagesListOptions) (*azcore.Request, error) { 49 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/usages" 50 urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location)) 51 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 52 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 53 if err != nil { 54 return nil, err 55 } 56 req.Telemetry(telemetryInfo) 57 query := req.URL.Query() 58 query.Set("api-version", "2020-07-01") 59 req.URL.RawQuery = query.Encode() 60 req.Header.Set("Accept", "application/json") 61 return req, nil 62} 63 64// listHandleResponse handles the List response. 65func (client *UsagesClient) listHandleResponse(resp *azcore.Response) (UsagesListResultResponse, error) { 66 var val *UsagesListResult 67 if err := resp.UnmarshalAsJSON(&val); err != nil { 68 return UsagesListResultResponse{}, err 69 } 70 return UsagesListResultResponse{RawResponse: resp.Response, UsagesListResult: val}, nil 71} 72 73// listHandleError handles the List error response. 74func (client *UsagesClient) listHandleError(resp *azcore.Response) error { 75 var err CloudError 76 if err := resp.UnmarshalAsJSON(&err); err != nil { 77 return err 78 } 79 return azcore.NewResponseError(&err, resp.Response) 80} 81