1
2
3
4
5
6
7
8 package subscriptions
9
10
11
12
13
14
15
16 import (
17 "context"
18 "github.com/Azure/go-autorest/autorest"
19 "github.com/Azure/go-autorest/autorest/azure"
20 "github.com/Azure/go-autorest/autorest/validation"
21 "github.com/Azure/go-autorest/tracing"
22 "net/http"
23 )
24
25 const (
26
27 DefaultBaseURI = "https://management.azure.com"
28 )
29
30
31 type BaseClient struct {
32 autorest.Client
33 BaseURI string
34 }
35
36
37 func New() BaseClient {
38 return NewWithBaseURI(DefaultBaseURI)
39 }
40
41
42
43 func NewWithBaseURI(baseURI string) BaseClient {
44 return BaseClient{
45 Client: autorest.NewClientWithUserAgent(UserAgent()),
46 BaseURI: baseURI,
47 }
48 }
49
50
51
52
53
54 func (client BaseClient) CheckResourceName(ctx context.Context, resourceNameDefinition *ResourceName) (result CheckResourceNameResult, err error) {
55 if tracing.IsEnabled() {
56 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.CheckResourceName")
57 defer func() {
58 sc := -1
59 if result.Response.Response != nil {
60 sc = result.Response.Response.StatusCode
61 }
62 tracing.EndSpan(ctx, sc, err)
63 }()
64 }
65 if err := validation.Validate([]validation.Validation{
66 {TargetValue: resourceNameDefinition,
67 Constraints: []validation.Constraint{{Target: "resourceNameDefinition", Name: validation.Null, Rule: false,
68 Chain: []validation.Constraint{{Target: "resourceNameDefinition.Name", Name: validation.Null, Rule: true, Chain: nil},
69 {Target: "resourceNameDefinition.Type", Name: validation.Null, Rule: true, Chain: nil},
70 }}}}}); err != nil {
71 return result, validation.NewError("subscriptions.BaseClient", "CheckResourceName", err.Error())
72 }
73
74 req, err := client.CheckResourceNamePreparer(ctx, resourceNameDefinition)
75 if err != nil {
76 err = autorest.NewErrorWithError(err, "subscriptions.BaseClient", "CheckResourceName", nil, "Failure preparing request")
77 return
78 }
79
80 resp, err := client.CheckResourceNameSender(req)
81 if err != nil {
82 result.Response = autorest.Response{Response: resp}
83 err = autorest.NewErrorWithError(err, "subscriptions.BaseClient", "CheckResourceName", resp, "Failure sending request")
84 return
85 }
86
87 result, err = client.CheckResourceNameResponder(resp)
88 if err != nil {
89 err = autorest.NewErrorWithError(err, "subscriptions.BaseClient", "CheckResourceName", resp, "Failure responding to request")
90 return
91 }
92
93 return
94 }
95
96
97 func (client BaseClient) CheckResourceNamePreparer(ctx context.Context, resourceNameDefinition *ResourceName) (*http.Request, error) {
98 const APIVersion = "2018-06-01"
99 queryParameters := map[string]interface{}{
100 "api-version": APIVersion,
101 }
102
103 preparer := autorest.CreatePreparer(
104 autorest.AsContentType("application/json; charset=utf-8"),
105 autorest.AsPost(),
106 autorest.WithBaseURL(client.BaseURI),
107 autorest.WithPath("/providers/Microsoft.Resources/checkResourceName"),
108 autorest.WithQueryParameters(queryParameters))
109 if resourceNameDefinition != nil {
110 preparer = autorest.DecoratePreparer(preparer,
111 autorest.WithJSON(resourceNameDefinition))
112 }
113 return preparer.Prepare((&http.Request{}).WithContext(ctx))
114 }
115
116
117
118 func (client BaseClient) CheckResourceNameSender(req *http.Request) (*http.Response, error) {
119 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
120 }
121
122
123
124 func (client BaseClient) CheckResourceNameResponder(resp *http.Response) (result CheckResourceNameResult, err error) {
125 err = autorest.Respond(
126 resp,
127 azure.WithErrorUnlessStatusCode(http.StatusOK),
128 autorest.ByUnmarshallingJSON(&result),
129 autorest.ByClosing())
130 result.Response = autorest.Response{Response: resp}
131 return
132 }
133
View as plain text