1// +build go1.13
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5// Code generated by Microsoft (R) AutoRest Code Generator.
6// Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
8package armnetwork
9
10import (
11	"context"
12	"errors"
13	"fmt"
14	"github.com/Azure/azure-sdk-for-go/sdk/armcore"
15	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
16	"net/http"
17	"net/url"
18	"strings"
19)
20
21// ExpressRouteServiceProvidersClient contains the methods for the ExpressRouteServiceProviders group.
22// Don't use this type directly, use NewExpressRouteServiceProvidersClient() instead.
23type ExpressRouteServiceProvidersClient struct {
24	con            *armcore.Connection
25	subscriptionID string
26}
27
28// NewExpressRouteServiceProvidersClient creates a new instance of ExpressRouteServiceProvidersClient with the specified values.
29func NewExpressRouteServiceProvidersClient(con *armcore.Connection, subscriptionID string) *ExpressRouteServiceProvidersClient {
30	return &ExpressRouteServiceProvidersClient{con: con, subscriptionID: subscriptionID}
31}
32
33// List - Gets all the available express route service providers.
34// If the operation fails it returns the *CloudError error type.
35func (client *ExpressRouteServiceProvidersClient) List(options *ExpressRouteServiceProvidersListOptions) ExpressRouteServiceProviderListResultPager {
36	return &expressRouteServiceProviderListResultPager{
37		pipeline: client.con.Pipeline(),
38		requester: func(ctx context.Context) (*azcore.Request, error) {
39			return client.listCreateRequest(ctx, options)
40		},
41		responder: client.listHandleResponse,
42		errorer:   client.listHandleError,
43		advancer: func(ctx context.Context, resp ExpressRouteServiceProviderListResultResponse) (*azcore.Request, error) {
44			return azcore.NewRequest(ctx, http.MethodGet, *resp.ExpressRouteServiceProviderListResult.NextLink)
45		},
46		statusCodes: []int{http.StatusOK},
47	}
48}
49
50// listCreateRequest creates the List request.
51func (client *ExpressRouteServiceProvidersClient) listCreateRequest(ctx context.Context, options *ExpressRouteServiceProvidersListOptions) (*azcore.Request, error) {
52	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/expressRouteServiceProviders"
53	if client.subscriptionID == "" {
54		return nil, errors.New("parameter client.subscriptionID cannot be empty")
55	}
56	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
57	req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath))
58	if err != nil {
59		return nil, err
60	}
61	req.Telemetry(telemetryInfo)
62	reqQP := req.URL.Query()
63	reqQP.Set("api-version", "2021-02-01")
64	req.URL.RawQuery = reqQP.Encode()
65	req.Header.Set("Accept", "application/json")
66	return req, nil
67}
68
69// listHandleResponse handles the List response.
70func (client *ExpressRouteServiceProvidersClient) listHandleResponse(resp *azcore.Response) (ExpressRouteServiceProviderListResultResponse, error) {
71	var val *ExpressRouteServiceProviderListResult
72	if err := resp.UnmarshalAsJSON(&val); err != nil {
73		return ExpressRouteServiceProviderListResultResponse{}, err
74	}
75	return ExpressRouteServiceProviderListResultResponse{RawResponse: resp.Response, ExpressRouteServiceProviderListResult: val}, nil
76}
77
78// listHandleError handles the List error response.
79func (client *ExpressRouteServiceProvidersClient) listHandleError(resp *azcore.Response) error {
80	body, err := resp.Payload()
81	if err != nil {
82		return azcore.NewResponseError(err, resp.Response)
83	}
84	errType := CloudError{raw: string(body)}
85	if err := resp.UnmarshalAsJSON(&errType); err != nil {
86		return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response)
87	}
88	return azcore.NewResponseError(&errType, resp.Response)
89}
90