1package network
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//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/tracing"
14	"net/http"
15)
16
17// ServiceTagsClient is the network Client
18type ServiceTagsClient struct {
19	BaseClient
20}
21
22// NewServiceTagsClient creates an instance of the ServiceTagsClient client.
23func NewServiceTagsClient(subscriptionID string) ServiceTagsClient {
24	return NewServiceTagsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewServiceTagsClientWithBaseURI creates an instance of the ServiceTagsClient client using a custom endpoint.  Use
28// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewServiceTagsClientWithBaseURI(baseURI string, subscriptionID string) ServiceTagsClient {
30	return ServiceTagsClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// List gets a list of service tag information resources.
34// Parameters:
35// location - the location that will be used as a reference for version (not as a filter based on location, you
36// will get the list of service tags with prefix details across all regions but limited to the cloud that your
37// subscription belongs to).
38func (client ServiceTagsClient) List(ctx context.Context, location string) (result ServiceTagsListResult, err error) {
39	if tracing.IsEnabled() {
40		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceTagsClient.List")
41		defer func() {
42			sc := -1
43			if result.Response.Response != nil {
44				sc = result.Response.Response.StatusCode
45			}
46			tracing.EndSpan(ctx, sc, err)
47		}()
48	}
49	req, err := client.ListPreparer(ctx, location)
50	if err != nil {
51		err = autorest.NewErrorWithError(err, "network.ServiceTagsClient", "List", nil, "Failure preparing request")
52		return
53	}
54
55	resp, err := client.ListSender(req)
56	if err != nil {
57		result.Response = autorest.Response{Response: resp}
58		err = autorest.NewErrorWithError(err, "network.ServiceTagsClient", "List", resp, "Failure sending request")
59		return
60	}
61
62	result, err = client.ListResponder(resp)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "network.ServiceTagsClient", "List", resp, "Failure responding to request")
65		return
66	}
67
68	return
69}
70
71// ListPreparer prepares the List request.
72func (client ServiceTagsClient) ListPreparer(ctx context.Context, location string) (*http.Request, error) {
73	pathParameters := map[string]interface{}{
74		"location":       autorest.Encode("path", location),
75		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
76	}
77
78	const APIVersion = "2019-12-01"
79	queryParameters := map[string]interface{}{
80		"api-version": APIVersion,
81	}
82
83	preparer := autorest.CreatePreparer(
84		autorest.AsGet(),
85		autorest.WithBaseURL(client.BaseURI),
86		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/serviceTags", pathParameters),
87		autorest.WithQueryParameters(queryParameters))
88	return preparer.Prepare((&http.Request{}).WithContext(ctx))
89}
90
91// ListSender sends the List request. The method will close the
92// http.Response Body if it receives an error.
93func (client ServiceTagsClient) ListSender(req *http.Request) (*http.Response, error) {
94	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
95}
96
97// ListResponder handles the response to the List request. The method always
98// closes the http.Response Body.
99func (client ServiceTagsClient) ListResponder(resp *http.Response) (result ServiceTagsListResult, err error) {
100	err = autorest.Respond(
101		resp,
102		azure.WithErrorUnlessStatusCode(http.StatusOK),
103		autorest.ByUnmarshallingJSON(&result),
104		autorest.ByClosing())
105	result.Response = autorest.Response{Response: resp}
106	return
107}
108