github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/expressrouteproviderportslocation_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 // ExpressRouteProviderPortsLocationClient contains the methods for the ExpressRouteProviderPortsLocation group. 24 // Don't use this type directly, use NewExpressRouteProviderPortsLocationClient() instead. 25 type ExpressRouteProviderPortsLocationClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewExpressRouteProviderPortsLocationClient creates a new instance of ExpressRouteProviderPortsLocationClient 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 NewExpressRouteProviderPortsLocationClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ExpressRouteProviderPortsLocationClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &ExpressRouteProviderPortsLocationClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // List - Retrieves all the ExpressRouteProviderPorts in a subscription. 48 // If the operation fails it returns an *azcore.ResponseError type. 49 // 50 // Generated from API version 2024-05-01 51 // - options - ExpressRouteProviderPortsLocationClientListOptions contains the optional parameters for the ExpressRouteProviderPortsLocationClient.List 52 // method. 53 func (client *ExpressRouteProviderPortsLocationClient) List(ctx context.Context, options *ExpressRouteProviderPortsLocationClientListOptions) (ExpressRouteProviderPortsLocationClientListResponse, error) { 54 var err error 55 const operationName = "ExpressRouteProviderPortsLocationClient.List" 56 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 57 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 58 defer func() { endSpan(err) }() 59 req, err := client.listCreateRequest(ctx, options) 60 if err != nil { 61 return ExpressRouteProviderPortsLocationClientListResponse{}, err 62 } 63 httpResp, err := client.internal.Pipeline().Do(req) 64 if err != nil { 65 return ExpressRouteProviderPortsLocationClientListResponse{}, err 66 } 67 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 68 err = runtime.NewResponseError(httpResp) 69 return ExpressRouteProviderPortsLocationClientListResponse{}, err 70 } 71 resp, err := client.listHandleResponse(httpResp) 72 return resp, err 73 } 74 75 // listCreateRequest creates the List request. 76 func (client *ExpressRouteProviderPortsLocationClient) listCreateRequest(ctx context.Context, options *ExpressRouteProviderPortsLocationClientListOptions) (*policy.Request, error) { 77 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/expressRouteProviderPorts" 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 if options != nil && options.Filter != nil { 88 reqQP.Set("$filter", *options.Filter) 89 } 90 reqQP.Set("api-version", "2024-05-01") 91 req.Raw().URL.RawQuery = reqQP.Encode() 92 req.Raw().Header["Accept"] = []string{"application/json"} 93 return req, nil 94 } 95 96 // listHandleResponse handles the List response. 97 func (client *ExpressRouteProviderPortsLocationClient) listHandleResponse(resp *http.Response) (ExpressRouteProviderPortsLocationClientListResponse, error) { 98 result := ExpressRouteProviderPortsLocationClientListResponse{} 99 if err := runtime.UnmarshalAsJSON(resp, &result.ExpressRouteProviderPortListResult); err != nil { 100 return ExpressRouteProviderPortsLocationClientListResponse{}, err 101 } 102 return result, nil 103 }