github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/loadbalancernetworkinterfaces_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 // LoadBalancerNetworkInterfacesClient contains the methods for the LoadBalancerNetworkInterfaces group. 24 // Don't use this type directly, use NewLoadBalancerNetworkInterfacesClient() instead. 25 type LoadBalancerNetworkInterfacesClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewLoadBalancerNetworkInterfacesClient creates a new instance of LoadBalancerNetworkInterfacesClient 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 NewLoadBalancerNetworkInterfacesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*LoadBalancerNetworkInterfacesClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &LoadBalancerNetworkInterfacesClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // NewListPager - Gets associated load balancer network interfaces. 48 // 49 // Generated from API version 2024-05-01 50 // - resourceGroupName - The name of the resource group. 51 // - loadBalancerName - The name of the load balancer. 52 // - options - LoadBalancerNetworkInterfacesClientListOptions contains the optional parameters for the LoadBalancerNetworkInterfacesClient.NewListPager 53 // method. 54 func (client *LoadBalancerNetworkInterfacesClient) NewListPager(resourceGroupName string, loadBalancerName string, options *LoadBalancerNetworkInterfacesClientListOptions) *runtime.Pager[LoadBalancerNetworkInterfacesClientListResponse] { 55 return runtime.NewPager(runtime.PagingHandler[LoadBalancerNetworkInterfacesClientListResponse]{ 56 More: func(page LoadBalancerNetworkInterfacesClientListResponse) bool { 57 return page.NextLink != nil && len(*page.NextLink) > 0 58 }, 59 Fetcher: func(ctx context.Context, page *LoadBalancerNetworkInterfacesClientListResponse) (LoadBalancerNetworkInterfacesClientListResponse, error) { 60 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LoadBalancerNetworkInterfacesClient.NewListPager") 61 nextLink := "" 62 if page != nil { 63 nextLink = *page.NextLink 64 } 65 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 66 return client.listCreateRequest(ctx, resourceGroupName, loadBalancerName, options) 67 }, nil) 68 if err != nil { 69 return LoadBalancerNetworkInterfacesClientListResponse{}, err 70 } 71 return client.listHandleResponse(resp) 72 }, 73 Tracer: client.internal.Tracer(), 74 }) 75 } 76 77 // listCreateRequest creates the List request. 78 func (client *LoadBalancerNetworkInterfacesClient) listCreateRequest(ctx context.Context, resourceGroupName string, loadBalancerName string, options *LoadBalancerNetworkInterfacesClientListOptions) (*policy.Request, error) { 79 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/networkInterfaces" 80 if resourceGroupName == "" { 81 return nil, errors.New("parameter resourceGroupName cannot be empty") 82 } 83 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 84 if loadBalancerName == "" { 85 return nil, errors.New("parameter loadBalancerName cannot be empty") 86 } 87 urlPath = strings.ReplaceAll(urlPath, "{loadBalancerName}", url.PathEscape(loadBalancerName)) 88 if client.subscriptionID == "" { 89 return nil, errors.New("parameter client.subscriptionID cannot be empty") 90 } 91 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 92 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 93 if err != nil { 94 return nil, err 95 } 96 reqQP := req.Raw().URL.Query() 97 reqQP.Set("api-version", "2024-05-01") 98 req.Raw().URL.RawQuery = reqQP.Encode() 99 req.Raw().Header["Accept"] = []string{"application/json"} 100 return req, nil 101 } 102 103 // listHandleResponse handles the List response. 104 func (client *LoadBalancerNetworkInterfacesClient) listHandleResponse(resp *http.Response) (LoadBalancerNetworkInterfacesClientListResponse, error) { 105 result := LoadBalancerNetworkInterfacesClientListResponse{} 106 if err := runtime.UnmarshalAsJSON(resp, &result.InterfaceListResult); err != nil { 107 return LoadBalancerNetworkInterfacesClientListResponse{}, err 108 } 109 return result, nil 110 }