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 armoperationalinsights
9
10import (
11	"context"
12	"errors"
13	"github.com/Azure/azure-sdk-for-go/sdk/armcore"
14	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
15	"net/http"
16	"net/url"
17	"strings"
18)
19
20// GatewaysClient contains the methods for the Gateways group.
21// Don't use this type directly, use NewGatewaysClient() instead.
22type GatewaysClient struct {
23	con            *armcore.Connection
24	subscriptionID string
25}
26
27// NewGatewaysClient creates a new instance of GatewaysClient with the specified values.
28func NewGatewaysClient(con *armcore.Connection, subscriptionID string) *GatewaysClient {
29	return &GatewaysClient{con: con, subscriptionID: subscriptionID}
30}
31
32// Delete - Delete a Log Analytics gateway.
33// If the operation fails it returns a generic error.
34func (client *GatewaysClient) Delete(ctx context.Context, resourceGroupName string, workspaceName string, gatewayID string, options *GatewaysDeleteOptions) (GatewaysDeleteResponse, error) {
35	req, err := client.deleteCreateRequest(ctx, resourceGroupName, workspaceName, gatewayID, options)
36	if err != nil {
37		return GatewaysDeleteResponse{}, err
38	}
39	resp, err := client.con.Pipeline().Do(req)
40	if err != nil {
41		return GatewaysDeleteResponse{}, err
42	}
43	if !resp.HasStatusCode(http.StatusOK) {
44		return GatewaysDeleteResponse{}, client.deleteHandleError(resp)
45	}
46	return GatewaysDeleteResponse{RawResponse: resp.Response}, nil
47}
48
49// deleteCreateRequest creates the Delete request.
50func (client *GatewaysClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, workspaceName string, gatewayID string, options *GatewaysDeleteOptions) (*azcore.Request, error) {
51	urlPath := "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/gateways/{gatewayId}"
52	if client.subscriptionID == "" {
53		return nil, errors.New("parameter client.subscriptionID cannot be empty")
54	}
55	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
56	if resourceGroupName == "" {
57		return nil, errors.New("parameter resourceGroupName cannot be empty")
58	}
59	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
60	if workspaceName == "" {
61		return nil, errors.New("parameter workspaceName cannot be empty")
62	}
63	urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName))
64	if gatewayID == "" {
65		return nil, errors.New("parameter gatewayID cannot be empty")
66	}
67	urlPath = strings.ReplaceAll(urlPath, "{gatewayId}", url.PathEscape(gatewayID))
68	req, err := azcore.NewRequest(ctx, http.MethodDelete, azcore.JoinPaths(client.con.Endpoint(), urlPath))
69	if err != nil {
70		return nil, err
71	}
72	req.Telemetry(telemetryInfo)
73	reqQP := req.URL.Query()
74	reqQP.Set("api-version", "2020-08-01")
75	req.URL.RawQuery = reqQP.Encode()
76	return req, nil
77}
78
79// deleteHandleError handles the Delete error response.
80func (client *GatewaysClient) deleteHandleError(resp *azcore.Response) error {
81	body, err := resp.Payload()
82	if err != nil {
83		return azcore.NewResponseError(err, resp.Response)
84	}
85	if len(body) == 0 {
86		return azcore.NewResponseError(errors.New(resp.Status), resp.Response)
87	}
88	return azcore.NewResponseError(errors.New(string(body)), resp.Response)
89}
90