1 package insights
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 QueryClient struct {
20 BaseClient
21 }
22
23
24 func NewQueryClient() QueryClient {
25 return NewQueryClientWithBaseURI(DefaultBaseURI)
26 }
27
28
29
30 func NewQueryClientWithBaseURI(baseURI string) QueryClient {
31 return QueryClient{NewWithBaseURI(baseURI)}
32 }
33
34
35
36
37
38
39
40
41
42 func (client QueryClient) Execute(ctx context.Context, appID string, body QueryBody) (result QueryResults, err error) {
43 if tracing.IsEnabled() {
44 ctx = tracing.StartSpan(ctx, fqdn+"/QueryClient.Execute")
45 defer func() {
46 sc := -1
47 if result.Response.Response != nil {
48 sc = result.Response.Response.StatusCode
49 }
50 tracing.EndSpan(ctx, sc, err)
51 }()
52 }
53 if err := validation.Validate([]validation.Validation{
54 {TargetValue: body,
55 Constraints: []validation.Constraint{{Target: "body.Query", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
56 return result, validation.NewError("insights.QueryClient", "Execute", err.Error())
57 }
58
59 req, err := client.ExecutePreparer(ctx, appID, body)
60 if err != nil {
61 err = autorest.NewErrorWithError(err, "insights.QueryClient", "Execute", nil, "Failure preparing request")
62 return
63 }
64
65 resp, err := client.ExecuteSender(req)
66 if err != nil {
67 result.Response = autorest.Response{Response: resp}
68 err = autorest.NewErrorWithError(err, "insights.QueryClient", "Execute", resp, "Failure sending request")
69 return
70 }
71
72 result, err = client.ExecuteResponder(resp)
73 if err != nil {
74 err = autorest.NewErrorWithError(err, "insights.QueryClient", "Execute", resp, "Failure responding to request")
75 return
76 }
77
78 return
79 }
80
81
82 func (client QueryClient) ExecutePreparer(ctx context.Context, appID string, body QueryBody) (*http.Request, error) {
83 pathParameters := map[string]interface{}{
84 "appId": autorest.Encode("path", appID),
85 }
86
87 preparer := autorest.CreatePreparer(
88 autorest.AsContentType("application/json; charset=utf-8"),
89 autorest.AsPost(),
90 autorest.WithBaseURL(client.BaseURI),
91 autorest.WithPathParameters("/apps/{appId}/query", pathParameters),
92 autorest.WithJSON(body))
93 return preparer.Prepare((&http.Request{}).WithContext(ctx))
94 }
95
96
97
98 func (client QueryClient) ExecuteSender(req *http.Request) (*http.Response, error) {
99 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
100 }
101
102
103
104 func (client QueryClient) ExecuteResponder(resp *http.Response) (result QueryResults, 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
View as plain text