github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/expressroutelinks_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  // ExpressRouteLinksClient contains the methods for the ExpressRouteLinks group.
    24  // Don't use this type directly, use NewExpressRouteLinksClient() instead.
    25  type ExpressRouteLinksClient struct {
    26  	internal       *arm.Client
    27  	subscriptionID string
    28  }
    29  
    30  // NewExpressRouteLinksClient creates a new instance of ExpressRouteLinksClient 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 NewExpressRouteLinksClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ExpressRouteLinksClient, error) {
    36  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	client := &ExpressRouteLinksClient{
    41  		subscriptionID: subscriptionID,
    42  		internal:       cl,
    43  	}
    44  	return client, nil
    45  }
    46  
    47  // Get - Retrieves the specified ExpressRouteLink resource.
    48  // If the operation fails it returns an *azcore.ResponseError type.
    49  //
    50  // Generated from API version 2024-05-01
    51  //   - resourceGroupName - The name of the resource group.
    52  //   - expressRoutePortName - The name of the ExpressRoutePort resource.
    53  //   - linkName - The name of the ExpressRouteLink resource.
    54  //   - options - ExpressRouteLinksClientGetOptions contains the optional parameters for the ExpressRouteLinksClient.Get method.
    55  func (client *ExpressRouteLinksClient) Get(ctx context.Context, resourceGroupName string, expressRoutePortName string, linkName string, options *ExpressRouteLinksClientGetOptions) (ExpressRouteLinksClientGetResponse, error) {
    56  	var err error
    57  	const operationName = "ExpressRouteLinksClient.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, resourceGroupName, expressRoutePortName, linkName, options)
    62  	if err != nil {
    63  		return ExpressRouteLinksClientGetResponse{}, err
    64  	}
    65  	httpResp, err := client.internal.Pipeline().Do(req)
    66  	if err != nil {
    67  		return ExpressRouteLinksClientGetResponse{}, err
    68  	}
    69  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
    70  		err = runtime.NewResponseError(httpResp)
    71  		return ExpressRouteLinksClientGetResponse{}, err
    72  	}
    73  	resp, err := client.getHandleResponse(httpResp)
    74  	return resp, err
    75  }
    76  
    77  // getCreateRequest creates the Get request.
    78  func (client *ExpressRouteLinksClient) getCreateRequest(ctx context.Context, resourceGroupName string, expressRoutePortName string, linkName string, options *ExpressRouteLinksClientGetOptions) (*policy.Request, error) {
    79  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ExpressRoutePorts/{expressRoutePortName}/links/{linkName}"
    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 resourceGroupName == "" {
    85  		return nil, errors.New("parameter resourceGroupName cannot be empty")
    86  	}
    87  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
    88  	if expressRoutePortName == "" {
    89  		return nil, errors.New("parameter expressRoutePortName cannot be empty")
    90  	}
    91  	urlPath = strings.ReplaceAll(urlPath, "{expressRoutePortName}", url.PathEscape(expressRoutePortName))
    92  	if linkName == "" {
    93  		return nil, errors.New("parameter linkName cannot be empty")
    94  	}
    95  	urlPath = strings.ReplaceAll(urlPath, "{linkName}", url.PathEscape(linkName))
    96  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
    97  	if err != nil {
    98  		return nil, err
    99  	}
   100  	reqQP := req.Raw().URL.Query()
   101  	reqQP.Set("api-version", "2024-05-01")
   102  	req.Raw().URL.RawQuery = reqQP.Encode()
   103  	req.Raw().Header["Accept"] = []string{"application/json"}
   104  	return req, nil
   105  }
   106  
   107  // getHandleResponse handles the Get response.
   108  func (client *ExpressRouteLinksClient) getHandleResponse(resp *http.Response) (ExpressRouteLinksClientGetResponse, error) {
   109  	result := ExpressRouteLinksClientGetResponse{}
   110  	if err := runtime.UnmarshalAsJSON(resp, &result.ExpressRouteLink); err != nil {
   111  		return ExpressRouteLinksClientGetResponse{}, err
   112  	}
   113  	return result, nil
   114  }
   115  
   116  // NewListPager - Retrieve the ExpressRouteLink sub-resources of the specified ExpressRoutePort resource.
   117  //
   118  // Generated from API version 2024-05-01
   119  //   - resourceGroupName - The name of the resource group.
   120  //   - expressRoutePortName - The name of the ExpressRoutePort resource.
   121  //   - options - ExpressRouteLinksClientListOptions contains the optional parameters for the ExpressRouteLinksClient.NewListPager
   122  //     method.
   123  func (client *ExpressRouteLinksClient) NewListPager(resourceGroupName string, expressRoutePortName string, options *ExpressRouteLinksClientListOptions) *runtime.Pager[ExpressRouteLinksClientListResponse] {
   124  	return runtime.NewPager(runtime.PagingHandler[ExpressRouteLinksClientListResponse]{
   125  		More: func(page ExpressRouteLinksClientListResponse) bool {
   126  			return page.NextLink != nil && len(*page.NextLink) > 0
   127  		},
   128  		Fetcher: func(ctx context.Context, page *ExpressRouteLinksClientListResponse) (ExpressRouteLinksClientListResponse, error) {
   129  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ExpressRouteLinksClient.NewListPager")
   130  			nextLink := ""
   131  			if page != nil {
   132  				nextLink = *page.NextLink
   133  			}
   134  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
   135  				return client.listCreateRequest(ctx, resourceGroupName, expressRoutePortName, options)
   136  			}, nil)
   137  			if err != nil {
   138  				return ExpressRouteLinksClientListResponse{}, err
   139  			}
   140  			return client.listHandleResponse(resp)
   141  		},
   142  		Tracer: client.internal.Tracer(),
   143  	})
   144  }
   145  
   146  // listCreateRequest creates the List request.
   147  func (client *ExpressRouteLinksClient) listCreateRequest(ctx context.Context, resourceGroupName string, expressRoutePortName string, options *ExpressRouteLinksClientListOptions) (*policy.Request, error) {
   148  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ExpressRoutePorts/{expressRoutePortName}/links"
   149  	if client.subscriptionID == "" {
   150  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   151  	}
   152  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   153  	if resourceGroupName == "" {
   154  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   155  	}
   156  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   157  	if expressRoutePortName == "" {
   158  		return nil, errors.New("parameter expressRoutePortName cannot be empty")
   159  	}
   160  	urlPath = strings.ReplaceAll(urlPath, "{expressRoutePortName}", url.PathEscape(expressRoutePortName))
   161  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   162  	if err != nil {
   163  		return nil, err
   164  	}
   165  	reqQP := req.Raw().URL.Query()
   166  	reqQP.Set("api-version", "2024-05-01")
   167  	req.Raw().URL.RawQuery = reqQP.Encode()
   168  	req.Raw().Header["Accept"] = []string{"application/json"}
   169  	return req, nil
   170  }
   171  
   172  // listHandleResponse handles the List response.
   173  func (client *ExpressRouteLinksClient) listHandleResponse(resp *http.Response) (ExpressRouteLinksClientListResponse, error) {
   174  	result := ExpressRouteLinksClientListResponse{}
   175  	if err := runtime.UnmarshalAsJSON(resp, &result.ExpressRouteLinkListResult); err != nil {
   176  		return ExpressRouteLinksClientListResponse{}, err
   177  	}
   178  	return result, nil
   179  }