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