-
Notifications
You must be signed in to change notification settings - Fork 21
/
exists.go
61 lines (49 loc) · 1.29 KB
/
exists.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package tables
import (
"context"
"fmt"
"net/http"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/odata"
)
type TableExistsResponse struct {
HttpResponse *client.Response
}
// Exists checks that the specified table exists
func (c Client) Exists(ctx context.Context, tableName string) (resp TableExistsResponse, err error) {
if tableName == "" {
return resp, fmt.Errorf("`tableName` cannot be an empty string")
}
opts := client.RequestOptions{
ContentType: "application/json",
ExpectedStatusCodes: []int{
http.StatusOK,
},
HttpMethod: http.MethodGet,
OptionsObject: tableExistsOptions{},
Path: fmt.Sprintf("/Tables('%s')", tableName),
}
req, err := c.Client.NewRequest(ctx, opts)
if err != nil {
err = fmt.Errorf("building request: %+v", err)
return
}
resp.HttpResponse, err = req.Execute(ctx)
if err != nil {
err = fmt.Errorf("executing request: %+v", err)
return
}
return
}
type tableExistsOptions struct{}
func (t tableExistsOptions) ToHeaders() *client.Headers {
headers := &client.Headers{}
headers.Append("Accept", "application/json;odata=nometadata")
return headers
}
func (t tableExistsOptions) ToOData() *odata.Query {
return nil
}
func (t tableExistsOptions) ToQuery() *client.QueryParams {
return nil
}