Passed
Push — master ( ad04e3...c5b8de )
by eval
01:47
created

cloudwatchlogs.*CloudwatchLogs.StartQuery   A

Complexity

Conditions 2

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nop 2
dl 0
loc 11
rs 9.95
c 0
b 0
f 0
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())
0 ignored issues
show
introduced by
can't check non-constant format in call to Errorf
Loading history...
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 {
0 ignored issues
show
introduced by
exported method StartQueryRequest.ToInput should have comment or be unexported
Loading history...
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 {
0 ignored issues
show
introduced by
exported type StartQueryResult should have comment or be unexported
Loading history...
71
	QueryID string
72
}
73
74
func NewStartQueryResult(o *SDK.StartQueryResponse) *StartQueryResult {
0 ignored issues
show
introduced by
exported function NewStartQueryResult should have comment or be unexported
Loading history...
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