github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/availableservicealiases_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  // AvailableServiceAliasesClient contains the methods for the AvailableServiceAliases group.
    24  // Don't use this type directly, use NewAvailableServiceAliasesClient() instead.
    25  type AvailableServiceAliasesClient struct {
    26  	internal       *arm.Client
    27  	subscriptionID string
    28  }
    29  
    30  // NewAvailableServiceAliasesClient creates a new instance of AvailableServiceAliasesClient 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 NewAvailableServiceAliasesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*AvailableServiceAliasesClient, error) {
    36  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	client := &AvailableServiceAliasesClient{
    41  		subscriptionID: subscriptionID,
    42  		internal:       cl,
    43  	}
    44  	return client, nil
    45  }
    46  
    47  // NewListPager - Gets all available service aliases for this subscription in this region.
    48  //
    49  // Generated from API version 2024-05-01
    50  //   - location - The location.
    51  //   - options - AvailableServiceAliasesClientListOptions contains the optional parameters for the AvailableServiceAliasesClient.NewListPager
    52  //     method.
    53  func (client *AvailableServiceAliasesClient) NewListPager(location string, options *AvailableServiceAliasesClientListOptions) *runtime.Pager[AvailableServiceAliasesClientListResponse] {
    54  	return runtime.NewPager(runtime.PagingHandler[AvailableServiceAliasesClientListResponse]{
    55  		More: func(page AvailableServiceAliasesClientListResponse) bool {
    56  			return page.NextLink != nil && len(*page.NextLink) > 0
    57  		},
    58  		Fetcher: func(ctx context.Context, page *AvailableServiceAliasesClientListResponse) (AvailableServiceAliasesClientListResponse, error) {
    59  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailableServiceAliasesClient.NewListPager")
    60  			nextLink := ""
    61  			if page != nil {
    62  				nextLink = *page.NextLink
    63  			}
    64  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
    65  				return client.listCreateRequest(ctx, location, options)
    66  			}, nil)
    67  			if err != nil {
    68  				return AvailableServiceAliasesClientListResponse{}, err
    69  			}
    70  			return client.listHandleResponse(resp)
    71  		},
    72  		Tracer: client.internal.Tracer(),
    73  	})
    74  }
    75  
    76  // listCreateRequest creates the List request.
    77  func (client *AvailableServiceAliasesClient) listCreateRequest(ctx context.Context, location string, options *AvailableServiceAliasesClientListOptions) (*policy.Request, error) {
    78  	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/availableServiceAliases"
    79  	if location == "" {
    80  		return nil, errors.New("parameter location cannot be empty")
    81  	}
    82  	urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location))
    83  	if client.subscriptionID == "" {
    84  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
    85  	}
    86  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
    87  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
    88  	if err != nil {
    89  		return nil, err
    90  	}
    91  	reqQP := req.Raw().URL.Query()
    92  	reqQP.Set("api-version", "2024-05-01")
    93  	req.Raw().URL.RawQuery = reqQP.Encode()
    94  	req.Raw().Header["Accept"] = []string{"application/json"}
    95  	return req, nil
    96  }
    97  
    98  // listHandleResponse handles the List response.
    99  func (client *AvailableServiceAliasesClient) listHandleResponse(resp *http.Response) (AvailableServiceAliasesClientListResponse, error) {
   100  	result := AvailableServiceAliasesClientListResponse{}
   101  	if err := runtime.UnmarshalAsJSON(resp, &result.AvailableServiceAliasesResult); err != nil {
   102  		return AvailableServiceAliasesClientListResponse{}, err
   103  	}
   104  	return result, nil
   105  }
   106  
   107  // NewListByResourceGroupPager - Gets all available service aliases for this resource group in this region.
   108  //
   109  // Generated from API version 2024-05-01
   110  //   - resourceGroupName - The name of the resource group.
   111  //   - location - The location.
   112  //   - options - AvailableServiceAliasesClientListByResourceGroupOptions contains the optional parameters for the AvailableServiceAliasesClient.NewListByResourceGroupPager
   113  //     method.
   114  func (client *AvailableServiceAliasesClient) NewListByResourceGroupPager(resourceGroupName string, location string, options *AvailableServiceAliasesClientListByResourceGroupOptions) *runtime.Pager[AvailableServiceAliasesClientListByResourceGroupResponse] {
   115  	return runtime.NewPager(runtime.PagingHandler[AvailableServiceAliasesClientListByResourceGroupResponse]{
   116  		More: func(page AvailableServiceAliasesClientListByResourceGroupResponse) bool {
   117  			return page.NextLink != nil && len(*page.NextLink) > 0
   118  		},
   119  		Fetcher: func(ctx context.Context, page *AvailableServiceAliasesClientListByResourceGroupResponse) (AvailableServiceAliasesClientListByResourceGroupResponse, error) {
   120  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AvailableServiceAliasesClient.NewListByResourceGroupPager")
   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.listByResourceGroupCreateRequest(ctx, resourceGroupName, location, options)
   127  			}, nil)
   128  			if err != nil {
   129  				return AvailableServiceAliasesClientListByResourceGroupResponse{}, err
   130  			}
   131  			return client.listByResourceGroupHandleResponse(resp)
   132  		},
   133  		Tracer: client.internal.Tracer(),
   134  	})
   135  }
   136  
   137  // listByResourceGroupCreateRequest creates the ListByResourceGroup request.
   138  func (client *AvailableServiceAliasesClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, location string, options *AvailableServiceAliasesClientListByResourceGroupOptions) (*policy.Request, error) {
   139  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/locations/{location}/availableServiceAliases"
   140  	if resourceGroupName == "" {
   141  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   142  	}
   143  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   144  	if location == "" {
   145  		return nil, errors.New("parameter location cannot be empty")
   146  	}
   147  	urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location))
   148  	if client.subscriptionID == "" {
   149  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   150  	}
   151  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   152  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   153  	if err != nil {
   154  		return nil, err
   155  	}
   156  	reqQP := req.Raw().URL.Query()
   157  	reqQP.Set("api-version", "2024-05-01")
   158  	req.Raw().URL.RawQuery = reqQP.Encode()
   159  	req.Raw().Header["Accept"] = []string{"application/json"}
   160  	return req, nil
   161  }
   162  
   163  // listByResourceGroupHandleResponse handles the ListByResourceGroup response.
   164  func (client *AvailableServiceAliasesClient) listByResourceGroupHandleResponse(resp *http.Response) (AvailableServiceAliasesClientListByResourceGroupResponse, error) {
   165  	result := AvailableServiceAliasesClientListByResourceGroupResponse{}
   166  	if err := runtime.UnmarshalAsJSON(resp, &result.AvailableServiceAliasesResult); err != nil {
   167  		return AvailableServiceAliasesClientListByResourceGroupResponse{}, err
   168  	}
   169  	return result, nil
   170  }