github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/peerexpressroutecircuitconnections_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  // PeerExpressRouteCircuitConnectionsClient contains the methods for the PeerExpressRouteCircuitConnections group.
    24  // Don't use this type directly, use NewPeerExpressRouteCircuitConnectionsClient() instead.
    25  type PeerExpressRouteCircuitConnectionsClient struct {
    26  	internal       *arm.Client
    27  	subscriptionID string
    28  }
    29  
    30  // NewPeerExpressRouteCircuitConnectionsClient creates a new instance of PeerExpressRouteCircuitConnectionsClient 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 NewPeerExpressRouteCircuitConnectionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*PeerExpressRouteCircuitConnectionsClient, error) {
    36  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	client := &PeerExpressRouteCircuitConnectionsClient{
    41  		subscriptionID: subscriptionID,
    42  		internal:       cl,
    43  	}
    44  	return client, nil
    45  }
    46  
    47  // Get - Gets the specified Peer Express Route Circuit Connection from the specified express route circuit.
    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  //   - circuitName - The name of the express route circuit.
    53  //   - peeringName - The name of the peering.
    54  //   - connectionName - The name of the peer express route circuit connection.
    55  //   - options - PeerExpressRouteCircuitConnectionsClientGetOptions contains the optional parameters for the PeerExpressRouteCircuitConnectionsClient.Get
    56  //     method.
    57  func (client *PeerExpressRouteCircuitConnectionsClient) Get(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *PeerExpressRouteCircuitConnectionsClientGetOptions) (PeerExpressRouteCircuitConnectionsClientGetResponse, error) {
    58  	var err error
    59  	const operationName = "PeerExpressRouteCircuitConnectionsClient.Get"
    60  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
    61  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
    62  	defer func() { endSpan(err) }()
    63  	req, err := client.getCreateRequest(ctx, resourceGroupName, circuitName, peeringName, connectionName, options)
    64  	if err != nil {
    65  		return PeerExpressRouteCircuitConnectionsClientGetResponse{}, err
    66  	}
    67  	httpResp, err := client.internal.Pipeline().Do(req)
    68  	if err != nil {
    69  		return PeerExpressRouteCircuitConnectionsClientGetResponse{}, err
    70  	}
    71  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
    72  		err = runtime.NewResponseError(httpResp)
    73  		return PeerExpressRouteCircuitConnectionsClientGetResponse{}, err
    74  	}
    75  	resp, err := client.getHandleResponse(httpResp)
    76  	return resp, err
    77  }
    78  
    79  // getCreateRequest creates the Get request.
    80  func (client *PeerExpressRouteCircuitConnectionsClient) getCreateRequest(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, connectionName string, options *PeerExpressRouteCircuitConnectionsClientGetOptions) (*policy.Request, error) {
    81  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/peerConnections/{connectionName}"
    82  	if resourceGroupName == "" {
    83  		return nil, errors.New("parameter resourceGroupName cannot be empty")
    84  	}
    85  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
    86  	if circuitName == "" {
    87  		return nil, errors.New("parameter circuitName cannot be empty")
    88  	}
    89  	urlPath = strings.ReplaceAll(urlPath, "{circuitName}", url.PathEscape(circuitName))
    90  	if peeringName == "" {
    91  		return nil, errors.New("parameter peeringName cannot be empty")
    92  	}
    93  	urlPath = strings.ReplaceAll(urlPath, "{peeringName}", url.PathEscape(peeringName))
    94  	if connectionName == "" {
    95  		return nil, errors.New("parameter connectionName cannot be empty")
    96  	}
    97  	urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName))
    98  	if client.subscriptionID == "" {
    99  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   100  	}
   101  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   102  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   103  	if err != nil {
   104  		return nil, err
   105  	}
   106  	reqQP := req.Raw().URL.Query()
   107  	reqQP.Set("api-version", "2024-05-01")
   108  	req.Raw().URL.RawQuery = reqQP.Encode()
   109  	req.Raw().Header["Accept"] = []string{"application/json"}
   110  	return req, nil
   111  }
   112  
   113  // getHandleResponse handles the Get response.
   114  func (client *PeerExpressRouteCircuitConnectionsClient) getHandleResponse(resp *http.Response) (PeerExpressRouteCircuitConnectionsClientGetResponse, error) {
   115  	result := PeerExpressRouteCircuitConnectionsClientGetResponse{}
   116  	if err := runtime.UnmarshalAsJSON(resp, &result.PeerExpressRouteCircuitConnection); err != nil {
   117  		return PeerExpressRouteCircuitConnectionsClientGetResponse{}, err
   118  	}
   119  	return result, nil
   120  }
   121  
   122  // NewListPager - Gets all global reach peer connections associated with a private peering in an express route circuit.
   123  //
   124  // Generated from API version 2024-05-01
   125  //   - resourceGroupName - The name of the resource group.
   126  //   - circuitName - The name of the circuit.
   127  //   - peeringName - The name of the peering.
   128  //   - options - PeerExpressRouteCircuitConnectionsClientListOptions contains the optional parameters for the PeerExpressRouteCircuitConnectionsClient.NewListPager
   129  //     method.
   130  func (client *PeerExpressRouteCircuitConnectionsClient) NewListPager(resourceGroupName string, circuitName string, peeringName string, options *PeerExpressRouteCircuitConnectionsClientListOptions) *runtime.Pager[PeerExpressRouteCircuitConnectionsClientListResponse] {
   131  	return runtime.NewPager(runtime.PagingHandler[PeerExpressRouteCircuitConnectionsClientListResponse]{
   132  		More: func(page PeerExpressRouteCircuitConnectionsClientListResponse) bool {
   133  			return page.NextLink != nil && len(*page.NextLink) > 0
   134  		},
   135  		Fetcher: func(ctx context.Context, page *PeerExpressRouteCircuitConnectionsClientListResponse) (PeerExpressRouteCircuitConnectionsClientListResponse, error) {
   136  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PeerExpressRouteCircuitConnectionsClient.NewListPager")
   137  			nextLink := ""
   138  			if page != nil {
   139  				nextLink = *page.NextLink
   140  			}
   141  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
   142  				return client.listCreateRequest(ctx, resourceGroupName, circuitName, peeringName, options)
   143  			}, nil)
   144  			if err != nil {
   145  				return PeerExpressRouteCircuitConnectionsClientListResponse{}, err
   146  			}
   147  			return client.listHandleResponse(resp)
   148  		},
   149  		Tracer: client.internal.Tracer(),
   150  	})
   151  }
   152  
   153  // listCreateRequest creates the List request.
   154  func (client *PeerExpressRouteCircuitConnectionsClient) listCreateRequest(ctx context.Context, resourceGroupName string, circuitName string, peeringName string, options *PeerExpressRouteCircuitConnectionsClientListOptions) (*policy.Request, error) {
   155  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteCircuits/{circuitName}/peerings/{peeringName}/peerConnections"
   156  	if resourceGroupName == "" {
   157  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   158  	}
   159  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   160  	if circuitName == "" {
   161  		return nil, errors.New("parameter circuitName cannot be empty")
   162  	}
   163  	urlPath = strings.ReplaceAll(urlPath, "{circuitName}", url.PathEscape(circuitName))
   164  	if peeringName == "" {
   165  		return nil, errors.New("parameter peeringName cannot be empty")
   166  	}
   167  	urlPath = strings.ReplaceAll(urlPath, "{peeringName}", url.PathEscape(peeringName))
   168  	if client.subscriptionID == "" {
   169  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   170  	}
   171  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   172  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   173  	if err != nil {
   174  		return nil, err
   175  	}
   176  	reqQP := req.Raw().URL.Query()
   177  	reqQP.Set("api-version", "2024-05-01")
   178  	req.Raw().URL.RawQuery = reqQP.Encode()
   179  	req.Raw().Header["Accept"] = []string{"application/json"}
   180  	return req, nil
   181  }
   182  
   183  // listHandleResponse handles the List response.
   184  func (client *PeerExpressRouteCircuitConnectionsClient) listHandleResponse(resp *http.Response) (PeerExpressRouteCircuitConnectionsClientListResponse, error) {
   185  	result := PeerExpressRouteCircuitConnectionsClientListResponse{}
   186  	if err := runtime.UnmarshalAsJSON(resp, &result.PeerExpressRouteCircuitConnectionListResult); err != nil {
   187  		return PeerExpressRouteCircuitConnectionsClientListResponse{}, err
   188  	}
   189  	return result, nil
   190  }