github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/interfaceloadbalancers_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 // InterfaceLoadBalancersClient contains the methods for the NetworkInterfaceLoadBalancers group. 24 // Don't use this type directly, use NewInterfaceLoadBalancersClient() instead. 25 type InterfaceLoadBalancersClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewInterfaceLoadBalancersClient creates a new instance of InterfaceLoadBalancersClient 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 NewInterfaceLoadBalancersClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*InterfaceLoadBalancersClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &InterfaceLoadBalancersClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // NewListPager - List all load balancers in a network interface. 48 // 49 // Generated from API version 2024-05-01 50 // - resourceGroupName - The name of the resource group. 51 // - networkInterfaceName - The name of the network interface. 52 // - options - InterfaceLoadBalancersClientListOptions contains the optional parameters for the InterfaceLoadBalancersClient.NewListPager 53 // method. 54 func (client *InterfaceLoadBalancersClient) NewListPager(resourceGroupName string, networkInterfaceName string, options *InterfaceLoadBalancersClientListOptions) *runtime.Pager[InterfaceLoadBalancersClientListResponse] { 55 return runtime.NewPager(runtime.PagingHandler[InterfaceLoadBalancersClientListResponse]{ 56 More: func(page InterfaceLoadBalancersClientListResponse) bool { 57 return page.NextLink != nil && len(*page.NextLink) > 0 58 }, 59 Fetcher: func(ctx context.Context, page *InterfaceLoadBalancersClientListResponse) (InterfaceLoadBalancersClientListResponse, error) { 60 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "InterfaceLoadBalancersClient.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, networkInterfaceName, options) 67 }, nil) 68 if err != nil { 69 return InterfaceLoadBalancersClientListResponse{}, 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 *InterfaceLoadBalancersClient) listCreateRequest(ctx context.Context, resourceGroupName string, networkInterfaceName string, options *InterfaceLoadBalancersClientListOptions) (*policy.Request, error) { 79 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}/loadBalancers" 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 networkInterfaceName == "" { 85 return nil, errors.New("parameter networkInterfaceName cannot be empty") 86 } 87 urlPath = strings.ReplaceAll(urlPath, "{networkInterfaceName}", url.PathEscape(networkInterfaceName)) 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 *InterfaceLoadBalancersClient) listHandleResponse(resp *http.Response) (InterfaceLoadBalancersClientListResponse, error) { 105 result := InterfaceLoadBalancersClientListResponse{} 106 if err := runtime.UnmarshalAsJSON(resp, &result.InterfaceLoadBalancerListResult); err != nil { 107 return InterfaceLoadBalancersClientListResponse{}, err 108 } 109 return result, nil 110 }