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 "github.com/Azure/azure-sdk-for-go/sdk/armcore" 13 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 14 "net/http" 15 "net/url" 16 "strings" 17) 18 19// ServiceTagsClient contains the methods for the ServiceTags group. 20// Don't use this type directly, use NewServiceTagsClient() instead. 21type ServiceTagsClient struct { 22 con *armcore.Connection 23 subscriptionID string 24} 25 26// NewServiceTagsClient creates a new instance of ServiceTagsClient with the specified values. 27func NewServiceTagsClient(con *armcore.Connection, subscriptionID string) *ServiceTagsClient { 28 return &ServiceTagsClient{con: con, subscriptionID: subscriptionID} 29} 30 31// List - Gets a list of service tag information resources. 32func (client *ServiceTagsClient) List(ctx context.Context, location string, options *ServiceTagsListOptions) (ServiceTagsListResultResponse, error) { 33 req, err := client.listCreateRequest(ctx, location, options) 34 if err != nil { 35 return ServiceTagsListResultResponse{}, err 36 } 37 resp, err := client.con.Pipeline().Do(req) 38 if err != nil { 39 return ServiceTagsListResultResponse{}, err 40 } 41 if !resp.HasStatusCode(http.StatusOK) { 42 return ServiceTagsListResultResponse{}, client.listHandleError(resp) 43 } 44 return client.listHandleResponse(resp) 45} 46 47// listCreateRequest creates the List request. 48func (client *ServiceTagsClient) listCreateRequest(ctx context.Context, location string, options *ServiceTagsListOptions) (*azcore.Request, error) { 49 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/serviceTags" 50 urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location)) 51 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 52 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 53 if err != nil { 54 return nil, err 55 } 56 req.Telemetry(telemetryInfo) 57 query := req.URL.Query() 58 query.Set("api-version", "2020-07-01") 59 req.URL.RawQuery = query.Encode() 60 req.Header.Set("Accept", "application/json") 61 return req, nil 62} 63 64// listHandleResponse handles the List response. 65func (client *ServiceTagsClient) listHandleResponse(resp *azcore.Response) (ServiceTagsListResultResponse, error) { 66 var val *ServiceTagsListResult 67 if err := resp.UnmarshalAsJSON(&val); err != nil { 68 return ServiceTagsListResultResponse{}, err 69 } 70 return ServiceTagsListResultResponse{RawResponse: resp.Response, ServiceTagsListResult: val}, nil 71} 72 73// listHandleError handles the List error response. 74func (client *ServiceTagsClient) listHandleError(resp *azcore.Response) error { 75 var err CloudError 76 if err := resp.UnmarshalAsJSON(&err); err != nil { 77 return err 78 } 79 return azcore.NewResponseError(&err, resp.Response) 80} 81