Passed
Pull Request — master (#6)
by eval
01:29
created

s3.ListObjectsRequest.ToInput   B

Complexity

Conditions 8

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 19
nop 0
dl 0
loc 30
rs 7.3333
c 0
b 0
f 0
1
package s3
2
3
import (
4
	"context"
5
6
	SDK "github.com/aws/aws-sdk-go-v2/service/s3"
7
8
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors"
9
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers"
10
)
11
12
// ListObjectsV2 executes `ListObjectsV2` operation.
13
func (svc *S3) ListObjectsV2(ctx context.Context, r ListObjectsRequest) (*ListObjectsResult, error) {
14
	out, err := svc.RawListObjectsV2(ctx, r.ToInput())
15
	if err != nil {
16
		err = svc.errWrap(errors.ErrorData{
17
			Err:          err,
18
			AWSOperation: "ListObjectsV2",
19
		})
20
		svc.Errorf(err.Error())
0 ignored issues
show
introduced by
can't check non-constant format in call to Errorf
Loading history...
21
		return nil, err
22
	}
23
	return NewListObjectsResultV2(out), nil
24
}
25
26
// ListObjectsRequest has parameters for `ListObjectsV2` operation.
27
type ListObjectsRequest struct {
28
	Bucket string
29
30
	// optional
31
	ContinuationToken string
32
	Delimiter         string
33
	EncodingType      string
34
	FetchOwner        bool
35
	MaxKeys           int64
36
	Prefix            string
37
	RequestPayer      string
38
	StartAfter        string
39
}
40
41
func (r ListObjectsRequest) ToInput() *SDK.ListObjectsV2Input {
0 ignored issues
show
introduced by
exported method ListObjectsRequest.ToInput should have comment or be unexported
Loading history...
42
	in := &SDK.ListObjectsV2Input{}
43
	if r.Bucket != "" {
44
		in.Bucket = pointers.String(r.Bucket)
45
	}
46
	if r.ContinuationToken != "" {
47
		in.ContinuationToken = pointers.String(r.ContinuationToken)
48
	}
49
	if r.Delimiter != "" {
50
		in.Delimiter = pointers.String(r.Delimiter)
51
	}
52
53
	in.EncodingType = SDK.EncodingType(r.EncodingType)
54
55
	if r.FetchOwner {
56
		in.FetchOwner = pointers.Bool(r.FetchOwner)
57
	}
58
	if r.MaxKeys != 0 {
59
		in.MaxKeys = pointers.Long64(r.MaxKeys)
60
	}
61
	if r.Prefix != "" {
62
		in.Prefix = pointers.String(r.Prefix)
63
	}
64
65
	in.RequestPayer = SDK.RequestPayer(r.RequestPayer)
66
67
	if r.StartAfter != "" {
68
		in.StartAfter = pointers.String(r.StartAfter)
69
	}
70
	return in
71
}
72
73
// ListObjectsResult contains data from ListObjectsV2.
74
type ListObjectsResult struct {
75
	CommonPrefixes        []string
76
	Contents              []Object
77
	ContinuationToken     string
78
	Delimiter             string
79
	EncodingType          EncodingType
80
	IsTruncated           bool
81
	KeyCount              int64
82
	MaxKeys               int64
83
	Name                  string
84
	NextContinuationToken string
85
	Prefix                string
86
	StartAfter            string
87
}
88
89
func NewListObjectsResultV2(output *SDK.ListObjectsV2Response) *ListObjectsResult {
0 ignored issues
show
introduced by
exported function NewListObjectsResultV2 should have comment or be unexported
Loading history...
90
	r := &ListObjectsResult{}
91
	if output == nil {
92
		return r
93
	}
94
95
	r.CommonPrefixes = newCommonPrefixes(output.CommonPrefixes)
96
97
	if len(output.Contents) != 0 {
98
		list := make([]Object, len(output.Contents))
99
		for i, v := range output.Contents {
100
			list[i] = NewObject(v)
101
		}
102
		r.Contents = list
103
	}
104
105
	if output.ContinuationToken != nil {
106
		r.ContinuationToken = *output.ContinuationToken
107
	}
108
	if output.Delimiter != nil {
109
		r.Delimiter = *output.Delimiter
110
	}
111
	if output.EncodingType != "" {
112
		r.EncodingType = EncodingType(output.EncodingType)
113
	}
114
	if output.IsTruncated != nil {
115
		r.IsTruncated = *output.IsTruncated
116
	}
117
	if output.KeyCount != nil {
118
		r.KeyCount = *output.KeyCount
119
	}
120
	if output.MaxKeys != nil {
121
		r.MaxKeys = *output.MaxKeys
122
	}
123
	if output.Name != nil {
124
		r.Name = *output.Name
125
	}
126
	if output.NextContinuationToken != nil {
127
		r.NextContinuationToken = *output.NextContinuationToken
128
	}
129
	if output.Prefix != nil {
130
		r.Prefix = *output.Prefix
131
	}
132
	if output.StartAfter != nil {
133
		r.StartAfter = *output.StartAfter
134
	}
135
	return r
136
}
137