github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/operations_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 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 14 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 17 "net/http" 18 ) 19 20 // OperationsClient contains the methods for the Operations group. 21 // Don't use this type directly, use NewOperationsClient() instead. 22 type OperationsClient struct { 23 internal *arm.Client 24 } 25 26 // NewOperationsClient creates a new instance of OperationsClient with the specified values. 27 // - credential - used to authorize requests. Usually a credential from azidentity. 28 // - options - pass nil to accept the default values. 29 func NewOperationsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*OperationsClient, error) { 30 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 31 if err != nil { 32 return nil, err 33 } 34 client := &OperationsClient{ 35 internal: cl, 36 } 37 return client, nil 38 } 39 40 // NewListPager - Lists all of the available Network Rest API operations. 41 // 42 // Generated from API version 2024-05-01 43 // - options - OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. 44 func (client *OperationsClient) NewListPager(options *OperationsClientListOptions) *runtime.Pager[OperationsClientListResponse] { 45 return runtime.NewPager(runtime.PagingHandler[OperationsClientListResponse]{ 46 More: func(page OperationsClientListResponse) bool { 47 return page.NextLink != nil && len(*page.NextLink) > 0 48 }, 49 Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { 50 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "OperationsClient.NewListPager") 51 nextLink := "" 52 if page != nil { 53 nextLink = *page.NextLink 54 } 55 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 56 return client.listCreateRequest(ctx, options) 57 }, nil) 58 if err != nil { 59 return OperationsClientListResponse{}, err 60 } 61 return client.listHandleResponse(resp) 62 }, 63 Tracer: client.internal.Tracer(), 64 }) 65 } 66 67 // listCreateRequest creates the List request. 68 func (client *OperationsClient) listCreateRequest(ctx context.Context, options *OperationsClientListOptions) (*policy.Request, error) { 69 urlPath := "/providers/Microsoft.Network/operations" 70 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 71 if err != nil { 72 return nil, err 73 } 74 reqQP := req.Raw().URL.Query() 75 reqQP.Set("api-version", "2024-05-01") 76 req.Raw().URL.RawQuery = reqQP.Encode() 77 req.Raw().Header["Accept"] = []string{"application/json"} 78 return req, nil 79 } 80 81 // listHandleResponse handles the List response. 82 func (client *OperationsClient) listHandleResponse(resp *http.Response) (OperationsClientListResponse, error) { 83 result := OperationsClientListResponse{} 84 if err := runtime.UnmarshalAsJSON(resp, &result.OperationListResult); err != nil { 85 return OperationsClientListResponse{}, err 86 } 87 return result, nil 88 }