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