github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/expressrouteportslocations_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  // ExpressRoutePortsLocationsClient contains the methods for the ExpressRoutePortsLocations group.
    24  // Don't use this type directly, use NewExpressRoutePortsLocationsClient() instead.
    25  type ExpressRoutePortsLocationsClient struct {
    26  	internal       *arm.Client
    27  	subscriptionID string
    28  }
    29  
    30  // NewExpressRoutePortsLocationsClient creates a new instance of ExpressRoutePortsLocationsClient 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 NewExpressRoutePortsLocationsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ExpressRoutePortsLocationsClient, error) {
    36  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	client := &ExpressRoutePortsLocationsClient{
    41  		subscriptionID: subscriptionID,
    42  		internal:       cl,
    43  	}
    44  	return client, nil
    45  }
    46  
    47  // Get - Retrieves a single ExpressRoutePort peering location, including the list of available bandwidths available at said
    48  // peering location.
    49  // If the operation fails it returns an *azcore.ResponseError type.
    50  //
    51  // Generated from API version 2024-05-01
    52  //   - locationName - Name of the requested ExpressRoutePort peering location.
    53  //   - options - ExpressRoutePortsLocationsClientGetOptions contains the optional parameters for the ExpressRoutePortsLocationsClient.Get
    54  //     method.
    55  func (client *ExpressRoutePortsLocationsClient) Get(ctx context.Context, locationName string, options *ExpressRoutePortsLocationsClientGetOptions) (ExpressRoutePortsLocationsClientGetResponse, error) {
    56  	var err error
    57  	const operationName = "ExpressRoutePortsLocationsClient.Get"
    58  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
    59  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
    60  	defer func() { endSpan(err) }()
    61  	req, err := client.getCreateRequest(ctx, locationName, options)
    62  	if err != nil {
    63  		return ExpressRoutePortsLocationsClientGetResponse{}, err
    64  	}
    65  	httpResp, err := client.internal.Pipeline().Do(req)
    66  	if err != nil {
    67  		return ExpressRoutePortsLocationsClientGetResponse{}, err
    68  	}
    69  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
    70  		err = runtime.NewResponseError(httpResp)
    71  		return ExpressRoutePortsLocationsClientGetResponse{}, err
    72  	}
    73  	resp, err := client.getHandleResponse(httpResp)
    74  	return resp, err
    75  }
    76  
    77  // getCreateRequest creates the Get request.
    78  func (client *ExpressRoutePortsLocationsClient) getCreateRequest(ctx context.Context, locationName string, options *ExpressRoutePortsLocationsClientGetOptions) (*policy.Request, error) {
    79  	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/ExpressRoutePortsLocations/{locationName}"
    80  	if client.subscriptionID == "" {
    81  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
    82  	}
    83  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
    84  	if locationName == "" {
    85  		return nil, errors.New("parameter locationName cannot be empty")
    86  	}
    87  	urlPath = strings.ReplaceAll(urlPath, "{locationName}", url.PathEscape(locationName))
    88  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
    89  	if err != nil {
    90  		return nil, err
    91  	}
    92  	reqQP := req.Raw().URL.Query()
    93  	reqQP.Set("api-version", "2024-05-01")
    94  	req.Raw().URL.RawQuery = reqQP.Encode()
    95  	req.Raw().Header["Accept"] = []string{"application/json"}
    96  	return req, nil
    97  }
    98  
    99  // getHandleResponse handles the Get response.
   100  func (client *ExpressRoutePortsLocationsClient) getHandleResponse(resp *http.Response) (ExpressRoutePortsLocationsClientGetResponse, error) {
   101  	result := ExpressRoutePortsLocationsClientGetResponse{}
   102  	if err := runtime.UnmarshalAsJSON(resp, &result.ExpressRoutePortsLocation); err != nil {
   103  		return ExpressRoutePortsLocationsClientGetResponse{}, err
   104  	}
   105  	return result, nil
   106  }
   107  
   108  // NewListPager - Retrieves all ExpressRoutePort peering locations. Does not return available bandwidths for each location.
   109  // Available bandwidths can only be obtained when retrieving a specific peering location.
   110  //
   111  // Generated from API version 2024-05-01
   112  //   - options - ExpressRoutePortsLocationsClientListOptions contains the optional parameters for the ExpressRoutePortsLocationsClient.NewListPager
   113  //     method.
   114  func (client *ExpressRoutePortsLocationsClient) NewListPager(options *ExpressRoutePortsLocationsClientListOptions) *runtime.Pager[ExpressRoutePortsLocationsClientListResponse] {
   115  	return runtime.NewPager(runtime.PagingHandler[ExpressRoutePortsLocationsClientListResponse]{
   116  		More: func(page ExpressRoutePortsLocationsClientListResponse) bool {
   117  			return page.NextLink != nil && len(*page.NextLink) > 0
   118  		},
   119  		Fetcher: func(ctx context.Context, page *ExpressRoutePortsLocationsClientListResponse) (ExpressRoutePortsLocationsClientListResponse, error) {
   120  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRoutePortsLocationsClient.NewListPager")
   121  			nextLink := ""
   122  			if page != nil {
   123  				nextLink = *page.NextLink
   124  			}
   125  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
   126  				return client.listCreateRequest(ctx, options)
   127  			}, nil)
   128  			if err != nil {
   129  				return ExpressRoutePortsLocationsClientListResponse{}, err
   130  			}
   131  			return client.listHandleResponse(resp)
   132  		},
   133  		Tracer: client.internal.Tracer(),
   134  	})
   135  }
   136  
   137  // listCreateRequest creates the List request.
   138  func (client *ExpressRoutePortsLocationsClient) listCreateRequest(ctx context.Context, options *ExpressRoutePortsLocationsClientListOptions) (*policy.Request, error) {
   139  	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/ExpressRoutePortsLocations"
   140  	if client.subscriptionID == "" {
   141  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   142  	}
   143  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   144  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   145  	if err != nil {
   146  		return nil, err
   147  	}
   148  	reqQP := req.Raw().URL.Query()
   149  	reqQP.Set("api-version", "2024-05-01")
   150  	req.Raw().URL.RawQuery = reqQP.Encode()
   151  	req.Raw().Header["Accept"] = []string{"application/json"}
   152  	return req, nil
   153  }
   154  
   155  // listHandleResponse handles the List response.
   156  func (client *ExpressRoutePortsLocationsClient) listHandleResponse(resp *http.Response) (ExpressRoutePortsLocationsClientListResponse, error) {
   157  	result := ExpressRoutePortsLocationsClientListResponse{}
   158  	if err := runtime.UnmarshalAsJSON(resp, &result.ExpressRoutePortsLocationListResult); err != nil {
   159  		return ExpressRoutePortsLocationsClientListResponse{}, err
   160  	}
   161  	return result, nil
   162  }