github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/availableendpointservices_client.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // Licensed under the MIT License. See License.txt in the project root for license information. 6 // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 package armnetwork 10 11 import ( 12 "context" 13 "errors" 14 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 18 "net/http" 19 "net/url" 20 "strings" 21 ) 22 23 // AvailableEndpointServicesClient contains the methods for the AvailableEndpointServices group. 24 // Don't use this type directly, use NewAvailableEndpointServicesClient() instead. 25 type AvailableEndpointServicesClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewAvailableEndpointServicesClient creates a new instance of AvailableEndpointServicesClient with the specified values. 31 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 32 // ID forms part of the URI for every service call. 33 // - credential - used to authorize requests. Usually a credential from azidentity. 34 // - options - pass nil to accept the default values. 35 func NewAvailableEndpointServicesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*AvailableEndpointServicesClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &AvailableEndpointServicesClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // NewListPager - List what values of endpoint services are available for use. 48 // 49 // Generated from API version 2024-05-01 50 // - location - The location to check available endpoint services. 51 // - options - AvailableEndpointServicesClientListOptions contains the optional parameters for the AvailableEndpointServicesClient.NewListPager 52 // method. 53 func (client *AvailableEndpointServicesClient) NewListPager(location string, options *AvailableEndpointServicesClientListOptions) *runtime.Pager[AvailableEndpointServicesClientListResponse] { 54 return runtime.NewPager(runtime.PagingHandler[AvailableEndpointServicesClientListResponse]{ 55 More: func(page AvailableEndpointServicesClientListResponse) bool { 56 return page.NextLink != nil && len(*page.NextLink) > 0 57 }, 58 Fetcher: func(ctx context.Context, page *AvailableEndpointServicesClientListResponse) (AvailableEndpointServicesClientListResponse, error) { 59 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailableEndpointServicesClient.NewListPager") 60 nextLink := "" 61 if page != nil { 62 nextLink = *page.NextLink 63 } 64 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 65 return client.listCreateRequest(ctx, location, options) 66 }, nil) 67 if err != nil { 68 return AvailableEndpointServicesClientListResponse{}, err 69 } 70 return client.listHandleResponse(resp) 71 }, 72 Tracer: client.internal.Tracer(), 73 }) 74 } 75 76 // listCreateRequest creates the List request. 77 func (client *AvailableEndpointServicesClient) listCreateRequest(ctx context.Context, location string, options *AvailableEndpointServicesClientListOptions) (*policy.Request, error) { 78 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/virtualNetworkAvailableEndpointServices" 79 if location == "" { 80 return nil, errors.New("parameter location cannot be empty") 81 } 82 urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location)) 83 if client.subscriptionID == "" { 84 return nil, errors.New("parameter client.subscriptionID cannot be empty") 85 } 86 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 87 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 88 if err != nil { 89 return nil, err 90 } 91 reqQP := req.Raw().URL.Query() 92 reqQP.Set("api-version", "2024-05-01") 93 req.Raw().URL.RawQuery = reqQP.Encode() 94 req.Raw().Header["Accept"] = []string{"application/json"} 95 return req, nil 96 } 97 98 // listHandleResponse handles the List response. 99 func (client *AvailableEndpointServicesClient) listHandleResponse(resp *http.Response) (AvailableEndpointServicesClientListResponse, error) { 100 result := AvailableEndpointServicesClientListResponse{} 101 if err := runtime.UnmarshalAsJSON(resp, &result.EndpointServicesListResult); err != nil { 102 return AvailableEndpointServicesClientListResponse{}, err 103 } 104 return result, nil 105 }