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 "errors" 13 "fmt" 14 "github.com/Azure/azure-sdk-for-go/sdk/armcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 16 "net/http" 17 "net/url" 18 "strings" 19) 20 21// AvailableEndpointServicesClient contains the methods for the AvailableEndpointServices group. 22// Don't use this type directly, use NewAvailableEndpointServicesClient() instead. 23type AvailableEndpointServicesClient struct { 24 con *armcore.Connection 25 subscriptionID string 26} 27 28// NewAvailableEndpointServicesClient creates a new instance of AvailableEndpointServicesClient with the specified values. 29func NewAvailableEndpointServicesClient(con *armcore.Connection, subscriptionID string) *AvailableEndpointServicesClient { 30 return &AvailableEndpointServicesClient{con: con, subscriptionID: subscriptionID} 31} 32 33// List - List what values of endpoint services are available for use. 34// If the operation fails it returns the *CloudError error type. 35func (client *AvailableEndpointServicesClient) List(location string, options *AvailableEndpointServicesListOptions) EndpointServicesListResultPager { 36 return &endpointServicesListResultPager{ 37 pipeline: client.con.Pipeline(), 38 requester: func(ctx context.Context) (*azcore.Request, error) { 39 return client.listCreateRequest(ctx, location, options) 40 }, 41 responder: client.listHandleResponse, 42 errorer: client.listHandleError, 43 advancer: func(ctx context.Context, resp EndpointServicesListResultResponse) (*azcore.Request, error) { 44 return azcore.NewRequest(ctx, http.MethodGet, *resp.EndpointServicesListResult.NextLink) 45 }, 46 statusCodes: []int{http.StatusOK}, 47 } 48} 49 50// listCreateRequest creates the List request. 51func (client *AvailableEndpointServicesClient) listCreateRequest(ctx context.Context, location string, options *AvailableEndpointServicesListOptions) (*azcore.Request, error) { 52 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/virtualNetworkAvailableEndpointServices" 53 if location == "" { 54 return nil, errors.New("parameter location cannot be empty") 55 } 56 urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location)) 57 if client.subscriptionID == "" { 58 return nil, errors.New("parameter client.subscriptionID cannot be empty") 59 } 60 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 61 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 62 if err != nil { 63 return nil, err 64 } 65 req.Telemetry(telemetryInfo) 66 reqQP := req.URL.Query() 67 reqQP.Set("api-version", "2021-02-01") 68 req.URL.RawQuery = reqQP.Encode() 69 req.Header.Set("Accept", "application/json") 70 return req, nil 71} 72 73// listHandleResponse handles the List response. 74func (client *AvailableEndpointServicesClient) listHandleResponse(resp *azcore.Response) (EndpointServicesListResultResponse, error) { 75 var val *EndpointServicesListResult 76 if err := resp.UnmarshalAsJSON(&val); err != nil { 77 return EndpointServicesListResultResponse{}, err 78 } 79 return EndpointServicesListResultResponse{RawResponse: resp.Response, EndpointServicesListResult: val}, nil 80} 81 82// listHandleError handles the List error response. 83func (client *AvailableEndpointServicesClient) listHandleError(resp *azcore.Response) error { 84 body, err := resp.Payload() 85 if err != nil { 86 return azcore.NewResponseError(err, resp.Response) 87 } 88 errType := CloudError{raw: string(body)} 89 if err := resp.UnmarshalAsJSON(&errType); err != nil { 90 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 91 } 92 return azcore.NewResponseError(&errType, resp.Response) 93} 94