1 package documentdb
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 type LocationsClient struct {
20 BaseClient
21 }
22
23
24 func NewLocationsClient(subscriptionID string) LocationsClient {
25 return NewLocationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewLocationsClientWithBaseURI(baseURI string, subscriptionID string) LocationsClient {
31 return LocationsClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37 func (client LocationsClient) Get(ctx context.Context, location string) (result LocationGetResult, err error) {
38 if tracing.IsEnabled() {
39 ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.Get")
40 defer func() {
41 sc := -1
42 if result.Response.Response != nil {
43 sc = result.Response.Response.StatusCode
44 }
45 tracing.EndSpan(ctx, sc, err)
46 }()
47 }
48 if err := validation.Validate([]validation.Validation{
49 {TargetValue: client.SubscriptionID,
50 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
51 return result, validation.NewError("documentdb.LocationsClient", "Get", err.Error())
52 }
53
54 req, err := client.GetPreparer(ctx, location)
55 if err != nil {
56 err = autorest.NewErrorWithError(err, "documentdb.LocationsClient", "Get", nil, "Failure preparing request")
57 return
58 }
59
60 resp, err := client.GetSender(req)
61 if err != nil {
62 result.Response = autorest.Response{Response: resp}
63 err = autorest.NewErrorWithError(err, "documentdb.LocationsClient", "Get", resp, "Failure sending request")
64 return
65 }
66
67 result, err = client.GetResponder(resp)
68 if err != nil {
69 err = autorest.NewErrorWithError(err, "documentdb.LocationsClient", "Get", resp, "Failure responding to request")
70 return
71 }
72
73 return
74 }
75
76
77 func (client LocationsClient) GetPreparer(ctx context.Context, location string) (*http.Request, error) {
78 pathParameters := map[string]interface{}{
79 "location": autorest.Encode("path", location),
80 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
81 }
82
83 const APIVersion = "2021-10-15"
84 queryParameters := map[string]interface{}{
85 "api-version": APIVersion,
86 }
87
88 preparer := autorest.CreatePreparer(
89 autorest.AsGet(),
90 autorest.WithBaseURL(client.BaseURI),
91 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}", pathParameters),
92 autorest.WithQueryParameters(queryParameters))
93 return preparer.Prepare((&http.Request{}).WithContext(ctx))
94 }
95
96
97
98 func (client LocationsClient) GetSender(req *http.Request) (*http.Response, error) {
99 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
100 }
101
102
103
104 func (client LocationsClient) GetResponder(resp *http.Response) (result LocationGetResult, err error) {
105 err = autorest.Respond(
106 resp,
107 azure.WithErrorUnlessStatusCode(http.StatusOK),
108 autorest.ByUnmarshallingJSON(&result),
109 autorest.ByClosing())
110 result.Response = autorest.Response{Response: resp}
111 return
112 }
113
114
115 func (client LocationsClient) List(ctx context.Context) (result LocationListResult, err error) {
116 if tracing.IsEnabled() {
117 ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.List")
118 defer func() {
119 sc := -1
120 if result.Response.Response != nil {
121 sc = result.Response.Response.StatusCode
122 }
123 tracing.EndSpan(ctx, sc, err)
124 }()
125 }
126 if err := validation.Validate([]validation.Validation{
127 {TargetValue: client.SubscriptionID,
128 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
129 return result, validation.NewError("documentdb.LocationsClient", "List", err.Error())
130 }
131
132 req, err := client.ListPreparer(ctx)
133 if err != nil {
134 err = autorest.NewErrorWithError(err, "documentdb.LocationsClient", "List", nil, "Failure preparing request")
135 return
136 }
137
138 resp, err := client.ListSender(req)
139 if err != nil {
140 result.Response = autorest.Response{Response: resp}
141 err = autorest.NewErrorWithError(err, "documentdb.LocationsClient", "List", resp, "Failure sending request")
142 return
143 }
144
145 result, err = client.ListResponder(resp)
146 if err != nil {
147 err = autorest.NewErrorWithError(err, "documentdb.LocationsClient", "List", resp, "Failure responding to request")
148 return
149 }
150
151 return
152 }
153
154
155 func (client LocationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
156 pathParameters := map[string]interface{}{
157 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
158 }
159
160 const APIVersion = "2021-10-15"
161 queryParameters := map[string]interface{}{
162 "api-version": APIVersion,
163 }
164
165 preparer := autorest.CreatePreparer(
166 autorest.AsGet(),
167 autorest.WithBaseURL(client.BaseURI),
168 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations", pathParameters),
169 autorest.WithQueryParameters(queryParameters))
170 return preparer.Prepare((&http.Request{}).WithContext(ctx))
171 }
172
173
174
175 func (client LocationsClient) ListSender(req *http.Request) (*http.Response, error) {
176 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
177 }
178
179
180
181 func (client LocationsClient) ListResponder(resp *http.Response) (result LocationListResult, err error) {
182 err = autorest.Respond(
183 resp,
184 azure.WithErrorUnlessStatusCode(http.StatusOK),
185 autorest.ByUnmarshallingJSON(&result),
186 autorest.ByClosing())
187 result.Response = autorest.Response{Response: resp}
188 return
189 }
190
View as plain text