| 1 |
package tables |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"net/http" |
| 6 |
|
| 7 |
"github.com/Azure/go-autorest/autorest" |
| 8 |
"github.com/Azure/go-autorest/autorest/azure" |
| 9 |
"github.com/Azure/go-autorest/autorest/validation" |
| 10 |
"github.com/tombuildsstuff/giovanni/storage/internal/endpoints" |
| 11 |
) |
| 12 |
|
| 13 |
// Exists checks that the specified table exists |
| 14 |
func (client Client) Exists(ctx context.Context, accountName, tableName string) (result autorest.Response, err error) { |
| 15 |
if accountName == "" { |
| 16 |
return result, validation.NewError("tables.Client", "Exists", "`accountName` cannot be an empty string.") |
| 17 |
} |
| 18 |
if tableName == "" { |
| 19 |
return result, validation.NewError("tables.Client", "Exists", "`tableName` cannot be an empty string.") |
| 20 |
} |
| 21 |
|
| 22 |
req, err := client.ExistsPreparer(ctx, accountName, tableName) |
| 23 |
if err != nil { |
| 24 |
err = autorest.NewErrorWithError(err, "tables.Client", "Exists", nil, "Failure preparing request") |
| 25 |
return |
| 26 |
} |
| 27 |
|
| 28 |
resp, err := client.ExistsSender(req) |
| 29 |
if err != nil { |
| 30 |
result = autorest.Response{Response: resp} |
| 31 |
err = autorest.NewErrorWithError(err, "tables.Client", "Exists", resp, "Failure sending request") |
| 32 |
return |
| 33 |
} |
| 34 |
|
| 35 |
result, err = client.ExistsResponder(resp) |
| 36 |
if err != nil { |
| 37 |
err = autorest.NewErrorWithError(err, "tables.Client", "Exists", resp, "Failure responding to request") |
| 38 |
return |
| 39 |
} |
| 40 |
|
| 41 |
return |
| 42 |
} |
| 43 |
|
| 44 |
// ExistsPreparer prepares the Exists request. |
| 45 |
func (client Client) ExistsPreparer(ctx context.Context, accountName, tableName string) (*http.Request, error) { |
| 46 |
pathParameters := map[string]interface{}{ |
| 47 |
"tableName": autorest.Encode("path", tableName), |
| 48 |
} |
| 49 |
|
| 50 |
headers := map[string]interface{}{ |
| 51 |
"x-ms-version": APIVersion, |
| 52 |
"Accept": "application/json;odata=nometadata", |
| 53 |
} |
| 54 |
|
| 55 |
// NOTE: whilst the API documentation says that API Version is Optional |
| 56 |
// apparently specifying it causes an "invalid content type" to always be returned |
| 57 |
// as such we omit it here :shrug: |
| 58 |
|
| 59 |
preparer := autorest.CreatePreparer( |
| 60 |
autorest.AsGet(), |
| 61 |
autorest.AsContentType("application/json"), |
| 62 |
autorest.WithBaseURL(endpoints.GetTableEndpoint(client.BaseURI, accountName)), |
| 63 |
autorest.WithPathParameters("/Tables('{tableName}')", pathParameters), |
| 64 |
autorest.WithHeaders(headers)) |
| 65 |
return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 66 |
} |
| 67 |
|
| 68 |
// ExistsSender sends the Exists request. The method will close the |
| 69 |
// http.Response Body if it receives an error. |
| 70 |
func (client Client) ExistsSender(req *http.Request) (*http.Response, error) { |
| 71 |
return autorest.SendWithSender(client, req, |
| 72 |
azure.DoRetryWithRegistration(client.Client)) |
| 73 |
} |
| 74 |
|
| 75 |
// ExistsResponder handles the response to the Exists request. The method always |
| 76 |
// closes the http.Response Body. |
| 77 |
func (client Client) ExistsResponder(resp *http.Response) (result autorest.Response, err error) { |
| 78 |
err = autorest.Respond( |
| 79 |
resp, |
| 80 |
client.ByInspecting(), |
| 81 |
azure.WithErrorUnlessStatusCode(http.StatusOK), |
| 82 |
autorest.ByClosing()) |
| 83 |
result = autorest.Response{Response: resp} |
| 84 |
|
| 85 |
return |
| 86 |
} |