|
1
|
|
|
package cloudwatchlogs |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"context" |
|
5
|
|
|
"time" |
|
6
|
|
|
|
|
7
|
|
|
SDK "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs" |
|
8
|
|
|
|
|
9
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors" |
|
10
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers" |
|
11
|
|
|
) |
|
12
|
|
|
|
|
13
|
|
|
// StartQuery executes `StartQuery` operation. |
|
14
|
|
|
func (svc *CloudwatchLogs) StartQuery(ctx context.Context, r StartQueryRequest) (*StartQueryResult, error) { |
|
15
|
|
|
out, err := svc.RawStartQuery(ctx, r.ToInput()) |
|
16
|
|
|
if err != nil { |
|
17
|
|
|
err = svc.errWrap(errors.ErrorData{ |
|
18
|
|
|
Err: err, |
|
19
|
|
|
AWSOperation: "StartQuery", |
|
20
|
|
|
}) |
|
21
|
|
|
svc.Errorf(err.Error()) |
|
|
|
|
|
|
22
|
|
|
return nil, err |
|
23
|
|
|
} |
|
24
|
|
|
return NewStartQueryResult(out), nil |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
// StartQueryRequest has parameters for `StartQuery` operation. |
|
28
|
|
|
type StartQueryRequest struct { |
|
29
|
|
|
QueryString string |
|
30
|
|
|
StartTime time.Time |
|
31
|
|
|
StartTimeInt int64 |
|
32
|
|
|
EndTime time.Time |
|
33
|
|
|
EndTimeInt int64 |
|
34
|
|
|
|
|
35
|
|
|
// optional |
|
36
|
|
|
Limit int64 |
|
37
|
|
|
LogGroupName string |
|
38
|
|
|
LogGroupNames []string |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
func (r StartQueryRequest) ToInput() *SDK.StartQueryInput { |
|
|
|
|
|
|
42
|
|
|
in := &SDK.StartQueryInput{} |
|
43
|
|
|
|
|
44
|
|
|
if r.QueryString != "" { |
|
45
|
|
|
in.QueryString = pointers.String(r.QueryString) |
|
46
|
|
|
} |
|
47
|
|
|
switch { |
|
48
|
|
|
case !r.StartTime.IsZero(): |
|
49
|
|
|
in.StartTime = pointers.Long64(r.StartTime.Unix()) |
|
50
|
|
|
case r.StartTimeInt != 0: |
|
51
|
|
|
in.StartTime = pointers.Long64(r.StartTimeInt) |
|
52
|
|
|
} |
|
53
|
|
|
switch { |
|
54
|
|
|
case !r.EndTime.IsZero(): |
|
55
|
|
|
in.EndTime = pointers.Long64(r.EndTime.Unix()) |
|
56
|
|
|
case r.EndTimeInt != 0: |
|
57
|
|
|
in.EndTime = pointers.Long64(r.EndTimeInt) |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if r.Limit != 0 { |
|
61
|
|
|
in.Limit = pointers.Long64(r.Limit) |
|
62
|
|
|
} |
|
63
|
|
|
if r.LogGroupName != "" { |
|
64
|
|
|
in.LogGroupName = pointers.String(r.LogGroupName) |
|
65
|
|
|
} |
|
66
|
|
|
in.LogGroupNames = r.LogGroupNames |
|
67
|
|
|
return in |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
type StartQueryResult struct { |
|
|
|
|
|
|
71
|
|
|
QueryID string |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
func NewStartQueryResult(o *SDK.StartQueryResponse) *StartQueryResult { |
|
|
|
|
|
|
75
|
|
|
result := &StartQueryResult{} |
|
76
|
|
|
if o == nil { |
|
77
|
|
|
return result |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
if o.QueryId != nil { |
|
81
|
|
|
result.QueryID = *o.QueryId |
|
82
|
|
|
} |
|
83
|
|
|
return result |
|
84
|
|
|
} |
|
85
|
|
|
|