Passed
Pull Request — master (#15)
by eval
01:49
created

dynamodb.MustNewAttributeValue   F

Complexity

Conditions 17

Size

Total Lines 48
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 44
nop 1
dl 0
loc 48
rs 1.8
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like dynamodb.MustNewAttributeValue often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
package dynamodb
2
3
import (
4
	"fmt"
5
	"strconv"
6
	"time"
7
8
	SDK "github.com/aws/aws-sdk-go-v2/service/dynamodb"
9
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers"
10
)
11
12
type ArchivalSummary struct {
0 ignored issues
show
introduced by
exported type ArchivalSummary should have comment or be unexported
Loading history...
13
	ArchivalBackupARN string
14
	ArchivalDateTime  time.Time
15
	ArchivalReason    string
16
}
17
18
func newArchivalSummary(o *SDK.ArchivalSummary) ArchivalSummary {
19
	result := ArchivalSummary{}
20
	if o == nil {
21
		return result
22
	}
23
24
	if o.ArchivalBackupArn != nil {
25
		result.ArchivalBackupARN = *o.ArchivalBackupArn
26
	}
27
	if o.ArchivalDateTime != nil {
28
		result.ArchivalDateTime = *o.ArchivalDateTime
29
	}
30
	if o.ArchivalReason != nil {
31
		result.ArchivalReason = *o.ArchivalReason
32
	}
33
	return result
34
}
35
36
type AttributeDefinition struct {
0 ignored issues
show
introduced by
exported type AttributeDefinition should have comment or be unexported
Loading history...
37
	AttributeName string
38
	AttributeType ScalarAttributeType
39
}
40
41
func newAttributeDefinitions(list []SDK.AttributeDefinition) []AttributeDefinition {
42
	if len(list) == 0 {
43
		return nil
44
	}
45
46
	results := make([]AttributeDefinition, len(list))
47
	for i, v := range list {
48
		results[i] = newAttributeDefinition(v)
49
	}
50
	return results
51
}
52
53
func newAttributeDefinition(o SDK.AttributeDefinition) AttributeDefinition {
54
	result := AttributeDefinition{}
55
56
	if o.AttributeName != nil {
57
		result.AttributeName = *o.AttributeName
58
	}
59
	result.AttributeType = ScalarAttributeType(o.AttributeType)
60
	return result
61
}
62
63
func (r AttributeDefinition) ToSDK() SDK.AttributeDefinition {
0 ignored issues
show
introduced by
exported method AttributeDefinition.ToSDK should have comment or be unexported
Loading history...
64
	o := SDK.AttributeDefinition{}
65
66
	if r.AttributeName != "" {
67
		o.AttributeName = pointers.String(r.AttributeName)
68
	}
69
70
	o.AttributeType = SDK.ScalarAttributeType(r.AttributeType)
71
	return o
72
}
73
74
type AttributeValue struct {
0 ignored issues
show
introduced by
exported type AttributeValue should have comment or be unexported
Loading history...
75
	Binary         []byte
76
	BinarySet      [][]byte
77
	List           []AttributeValue
78
	Map            map[string]AttributeValue
79
	Number         string
80
	NumberInt      int64
81
	NumberFloat    float64
82
	NumberSet      []string
83
	NumberSetInt   []int64
84
	NumberSetFloat []float64
85
	Null           bool
86
	String         string
87
	StringSet      []string
88
89
	Bool      bool
90
	HasBool   bool
91
	HasNumber bool
92
}
93
94
// MustNewAttributeValue creates AttributeValue from given value.
95
func MustNewAttributeValue(v interface{}) AttributeValue {
96
	result := AttributeValue{}
97
98
	switch vv := v.(type) {
99
	case []byte:
100
		result.Binary = vv
101
	case [][]byte:
102
		result.BinarySet = vv
103
	case string:
104
		result.String = vv
105
	case []string:
106
		result.StringSet = vv
107
	case bool:
108
		result.Bool = vv
109
		result.HasBool = true
110
	case int:
111
		result.NumberInt = int64(vv)
112
		result.HasNumber = true
113
	case int32:
114
		result.NumberInt = int64(vv)
115
		result.HasNumber = true
116
	case int64:
117
		result.NumberInt = vv
118
		result.HasNumber = true
119
	case float32:
120
		result.NumberFloat = float64(vv)
121
		result.HasNumber = true
122
	case float64:
123
		result.NumberFloat = vv
124
		result.HasNumber = true
125
	case []int64:
126
		result.NumberSetInt = vv
127
	case []float64:
128
		result.NumberSetFloat = vv
129
	case map[string]interface{}:
130
		m := make(map[string]AttributeValue, len(vv))
131
		for k, v := range vv {
132
			m[k] = MustNewAttributeValue(v)
133
		}
134
		result.Map = m
135
	default:
136
		if v == nil {
137
			result.Null = true
138
			return result
139
		}
140
		panic(fmt.Sprintf("[MustNewAttributeValue] cannot parse the given value type: [%t]", v))
141
	}
142
	return result
143
}
144
145
func newAttributeValue(o SDK.AttributeValue) AttributeValue {
146
	result := AttributeValue{}
147
148
	switch {
149
	case len(o.B) != 0:
150
		result.Binary = o.B
151
	case len(o.BS) != 0:
152
		result.BinarySet = o.BS
153
	case len(o.L) != 0:
154
		result.List = newAttributeValueList(o.L)
155
	case len(o.M) != 0:
156
		result.Map = newAttributeValueMap(o.M)
157
	case o.N != nil:
158
		result.Number = *o.N
159
		result.HasNumber = true
160
	case len(o.NS) != 0:
161
		result.NumberSet = o.NS
162
	case o.NULL != nil:
163
		result.Null = *o.NULL
164
	case o.S != nil:
165
		result.String = *o.S
166
	case len(o.SS) != 0:
167
		result.StringSet = o.SS
168
	case o.BOOL != nil:
169
		result.Bool = *o.BOOL
170
		result.HasBool = true
171
	}
172
	return result
173
}
174
175
func newAttributeValueList(list []SDK.AttributeValue) []AttributeValue {
176
	if len(list) == 0 {
177
		return nil
178
	}
179
180
	results := make([]AttributeValue, len(list))
181
	for i, v := range list {
182
		results[i] = newAttributeValue(v)
183
	}
184
	return results
185
}
186
187
func newAttributeValueMap(o map[string]SDK.AttributeValue) map[string]AttributeValue {
188
	if len(o) == 0 {
189
		return nil
190
	}
191
192
	m := make(map[string]AttributeValue, len(o))
193
	for key, val := range o {
194
		m[key] = newAttributeValue(val)
195
	}
196
	return m
197
}
198
199
func (r AttributeValue) ToSDK() SDK.AttributeValue {
0 ignored issues
show
introduced by
exported method AttributeValue.ToSDK should have comment or be unexported
Loading history...
200
	o := SDK.AttributeValue{}
201
202
	switch {
203
	case len(r.Binary) != 0:
204
		o.B = r.Binary
205
	case len(r.BinarySet) != 0:
206
		o.BS = r.BinarySet
207
	case len(r.List) != 0:
208
		list := make([]SDK.AttributeValue, len(r.List))
209
		for i, v := range r.List {
210
			list[i] = v.ToSDK()
211
		}
212
		o.L = list
213
	case len(r.Map) != 0:
214
		m := make(map[string]SDK.AttributeValue, len(r.Map))
215
		for key, val := range r.Map {
216
			m[key] = val.ToSDK()
217
		}
218
		o.M = m
219
	case r.Number != "":
220
		o.N = pointers.String(r.Number)
221
	case r.NumberInt != 0:
222
		o.N = pointers.String(strconv.FormatInt(r.NumberInt, 10))
223
	case r.NumberFloat != 0:
224
		o.N = pointers.String(strconv.FormatFloat(r.NumberFloat, 'f', -1, 64))
225
	case r.HasNumber:
226
		o.N = pointers.String("0")
227
	case len(r.NumberSet) != 0:
228
		o.NS = r.NumberSet
229
	case len(r.NumberSetInt) != 0:
230
		list := make([]string, len(r.NumberSetInt))
231
		for i, v := range r.NumberSetInt {
232
			list[i] = strconv.FormatInt(v, 10)
233
		}
234
		o.NS = list
235
	case len(r.NumberSetFloat) != 0:
236
		list := make([]string, len(r.NumberSetFloat))
237
		for i, v := range r.NumberSetFloat {
238
			list[i] = strconv.FormatFloat(v, 'f', -1, 64)
239
		}
240
		o.NS = list
241
	case r.String != "":
242
		o.S = pointers.String(r.String)
243
	case len(r.StringSet) != 0:
244
		o.SS = r.StringSet
245
	case r.HasBool,
246
		r.Bool:
247
		o.BOOL = pointers.Bool(r.Bool)
248
	case r.Null:
249
		o.NULL = pointers.Bool(r.Null)
250
	}
251
	return o
252
}
253
254
func (r AttributeValue) GetValue() interface{} {
0 ignored issues
show
introduced by
exported method AttributeValue.GetValue should have comment or be unexported
Loading history...
255
	switch {
256
	case len(r.Binary) != 0:
257
		return r.Binary
258
	case len(r.BinarySet) != 0:
259
		return r.BinarySet
260
	case len(r.List) != 0:
261
		list := make([]interface{}, len(r.List))
262
		for i, v := range r.List {
263
			list[i] = v.GetValue()
264
		}
265
		return list
266
	case len(r.Map) != 0:
267
		m := make(map[string]interface{}, len(r.Map))
268
		for key, val := range r.Map {
269
			m[key] = val.GetValue()
270
		}
271
		return m
272
	case r.Number != "":
273
		v, _ := strconv.Atoi(r.Number)
274
		return v
275
	case r.NumberInt != 0:
276
		return r.NumberInt
277
	case r.NumberFloat != 0:
278
		return r.NumberFloat
279
	case r.HasNumber:
280
		return 0
281
	case len(r.NumberSet) != 0:
282
		list := make([]int, len(r.NumberSet))
283
		for i, v := range r.NumberSet {
284
			list[i], _ = strconv.Atoi(v)
285
		}
286
		return list
287
	case len(r.NumberSetInt) != 0:
288
		return r.NumberSetInt
289
	case len(r.NumberSetFloat) != 0:
290
		return r.NumberSetFloat
291
	case r.String != "":
292
		return r.String
293
	case len(r.StringSet) != 0:
294
		return r.StringSet
295
	case r.HasBool,
296
		r.Bool:
297
		return r.Bool
298
	case r.Null:
299
		return newArchivalSummary
300
	}
301
	return nil
302
}
303
304
func (r AttributeValue) hasValue() bool {
305
	switch {
306
	case r.HasNumber,
307
		r.HasBool,
308
		r.Bool,
309
		r.Null,
310
		r.Number != "",
311
		r.NumberInt != 0,
312
		r.NumberFloat != 0,
313
		r.String != "",
314
		len(r.Binary) != 0,
315
		len(r.BinarySet) != 0,
316
		len(r.List) != 0,
317
		len(r.Map) != 0,
318
		len(r.NumberSet) != 0,
319
		len(r.NumberSetInt) != 0,
320
		len(r.NumberSetFloat) != 0,
321
		len(r.StringSet) != 0:
322
		return true
323
	}
324
	return false
325
}
326
327
type BillingModeSummary struct {
0 ignored issues
show
introduced by
exported type BillingModeSummary should have comment or be unexported
Loading history...
328
	BillingMode                       BillingMode
329
	LastUpdateToPayPerRequestDateTime time.Time
330
}
331
332
func newBillingModeSummary(o *SDK.BillingModeSummary) BillingModeSummary {
333
	result := BillingModeSummary{}
334
	if o == nil {
335
		return result
336
	}
337
338
	if o.LastUpdateToPayPerRequestDateTime != nil {
339
		result.LastUpdateToPayPerRequestDateTime = *o.LastUpdateToPayPerRequestDateTime
340
	}
341
342
	result.BillingMode = BillingMode(o.BillingMode)
343
	return result
344
}
345
346
type Capacity struct {
0 ignored issues
show
introduced by
exported type Capacity should have comment or be unexported
Loading history...
347
	CapacityUnits      float64
348
	ReadCapacityUnits  float64
349
	WriteCapacityUnits float64
350
}
351
352
func newCapacity(o *SDK.Capacity) Capacity {
353
	result := Capacity{}
354
	if o == nil {
355
		return result
356
	}
357
358
	if o.CapacityUnits != nil {
359
		result.CapacityUnits = *o.CapacityUnits
360
	}
361
	if o.ReadCapacityUnits != nil {
362
		result.ReadCapacityUnits = *o.ReadCapacityUnits
363
	}
364
	if o.WriteCapacityUnits != nil {
365
		result.WriteCapacityUnits = *o.WriteCapacityUnits
366
	}
367
	return result
368
}
369
370
func newCapacityMap(m map[string]SDK.Capacity) map[string]Capacity {
371
	if m == nil {
372
		return nil
373
	}
374
375
	result := make(map[string]Capacity, len(m))
376
	for key, val := range m {
377
		val := val
378
		result[key] = newCapacity(&val)
379
	}
380
	return result
381
}
382
383
type Condition struct {
0 ignored issues
show
introduced by
exported type Condition should have comment or be unexported
Loading history...
384
	ComparisonOperator ComparisonOperator
385
386
	// optional
387
	AttributeValueList []AttributeValue
388
}
389
390
func (r Condition) ToSDK() SDK.Condition {
0 ignored issues
show
introduced by
exported method Condition.ToSDK should have comment or be unexported
Loading history...
391
	o := SDK.Condition{}
392
393
	o.ComparisonOperator = SDK.ComparisonOperator(r.ComparisonOperator)
394
395
	if len(r.AttributeValueList) != 0 {
396
		list := make([]SDK.AttributeValue, len(r.AttributeValueList))
397
		for i, v := range r.AttributeValueList {
398
			list[i] = v.ToSDK()
399
		}
400
		o.AttributeValueList = list
401
	}
402
403
	return o
404
}
405
406
type ConsumedCapacity struct {
0 ignored issues
show
introduced by
exported type ConsumedCapacity should have comment or be unexported
Loading history...
407
	CapacityUnits          float64
408
	GlobalSecondaryIndexes map[string]Capacity
409
	LocalSecondaryIndexes  map[string]Capacity
410
	ReadCapacityUnits      float64
411
	Table                  Capacity
412
	TableName              string
413
	WriteCapacityUnits     float64
414
}
415
416
func newConsumedCapacities(list []SDK.ConsumedCapacity) []ConsumedCapacity {
417
	if len(list) == 0 {
418
		return nil
419
	}
420
421
	result := make([]ConsumedCapacity, len(list))
422
	for i, v := range list {
423
		result[i] = newConsumedCapacity(v)
424
	}
425
	return result
426
}
427
428
func newConsumedCapacity(o SDK.ConsumedCapacity) ConsumedCapacity {
429
	result := ConsumedCapacity{}
430
431
	if o.CapacityUnits != nil {
432
		result.CapacityUnits = *o.CapacityUnits
433
	}
434
	if o.ReadCapacityUnits != nil {
435
		result.ReadCapacityUnits = *o.ReadCapacityUnits
436
	}
437
	if o.TableName != nil {
438
		result.TableName = *o.TableName
439
	}
440
	if o.WriteCapacityUnits != nil {
441
		result.WriteCapacityUnits = *o.WriteCapacityUnits
442
	}
443
444
	result.GlobalSecondaryIndexes = newCapacityMap(o.GlobalSecondaryIndexes)
445
	result.LocalSecondaryIndexes = newCapacityMap(o.LocalSecondaryIndexes)
446
	result.Table = newCapacity(o.Table)
447
	return result
448
}
449
450
type ExpectedAttributeValue struct {
0 ignored issues
show
introduced by
exported type ExpectedAttributeValue should have comment or be unexported
Loading history...
451
	AttributeValueList []AttributeValue   `type:"list"`
452
	ComparisonOperator ComparisonOperator `type:"string" enum:"true"`
453
	Exists             bool               `type:"boolean"`
454
	Value              AttributeValue     `type:"structure"`
455
}
456
457
func (r ExpectedAttributeValue) ToSDK() SDK.ExpectedAttributeValue {
0 ignored issues
show
introduced by
exported method ExpectedAttributeValue.ToSDK should have comment or be unexported
Loading history...
458
	o := SDK.ExpectedAttributeValue{}
459
460
	if len(r.AttributeValueList) != 0 {
461
		list := make([]SDK.AttributeValue, 0, len(r.AttributeValueList))
462
		for _, v := range r.AttributeValueList {
463
			if v.hasValue() {
464
				list = append(list, v.ToSDK())
465
			}
466
		}
467
		o.AttributeValueList = list
468
	}
469
470
	if r.Exists {
471
		o.Exists = pointers.Bool(r.Exists)
472
	}
473
474
	o.ComparisonOperator = SDK.ComparisonOperator(r.ComparisonOperator)
475
476
	if r.Value.hasValue() {
477
		v := r.Value.ToSDK()
478
		o.Value = &v
479
	}
480
481
	return o
482
}
483
484
type GlobalSecondaryIndex struct {
0 ignored issues
show
introduced by
exported type GlobalSecondaryIndex should have comment or be unexported
Loading history...
485
	IndexName  string
486
	KeySchema  []KeySchemaElement
487
	Projection Projection
488
489
	// optional
490
	ProvisionedThroughput ProvisionedThroughput
491
}
492
493
func (r GlobalSecondaryIndex) ToSDK() SDK.GlobalSecondaryIndex {
0 ignored issues
show
introduced by
exported method GlobalSecondaryIndex.ToSDK should have comment or be unexported
Loading history...
494
	o := SDK.GlobalSecondaryIndex{}
495
496
	if r.IndexName != "" {
497
		o.IndexName = pointers.String(r.IndexName)
498
	}
499
500
	if r.Projection.hasValue() {
501
		v := r.Projection.ToSDK()
502
		o.Projection = &v
503
	}
504
	if r.ProvisionedThroughput.hasValue() {
505
		v := r.ProvisionedThroughput.ToSDK()
506
		o.ProvisionedThroughput = &v
507
	}
508
509
	if len(r.KeySchema) != 0 {
510
		list := make([]SDK.KeySchemaElement, len(r.KeySchema))
511
		for i, v := range r.KeySchema {
512
			list[i] = v.ToSDK()
513
		}
514
		o.KeySchema = list
515
	}
516
	return o
517
}
518
519
// Represents the properties of a global secondary index.
0 ignored issues
show
introduced by
comment on exported type GlobalSecondaryIndexDescription should be of the form "GlobalSecondaryIndexDescription ..." (with optional leading article)
Loading history...
520
type GlobalSecondaryIndexDescription struct {
521
	Backfilling           bool
522
	IndexARN              string
523
	IndexName             string
524
	IndexSizeBytes        int64
525
	IndexStatus           IndexStatus
526
	ItemCount             int64
527
	KeySchema             []KeySchemaElement
528
	Projection            Projection
529
	ProvisionedThroughput ProvisionedThroughputDescription
530
}
531
532
func newGlobalSecondaryIndexDescriptions(list []SDK.GlobalSecondaryIndexDescription) []GlobalSecondaryIndexDescription {
533
	if len(list) == 0 {
534
		return nil
535
	}
536
537
	result := make([]GlobalSecondaryIndexDescription, len(list))
538
	for i, v := range list {
539
		result[i] = newGlobalSecondaryIndexDescription(v)
540
	}
541
	return result
542
}
543
544
func newGlobalSecondaryIndexDescription(o SDK.GlobalSecondaryIndexDescription) GlobalSecondaryIndexDescription {
545
	result := GlobalSecondaryIndexDescription{}
546
547
	if o.Backfilling != nil {
548
		result.Backfilling = *o.Backfilling
549
	}
550
	if o.IndexArn != nil {
551
		result.IndexARN = *o.IndexArn
552
	}
553
	if o.IndexName != nil {
554
		result.IndexName = *o.IndexName
555
	}
556
	if o.IndexSizeBytes != nil {
557
		result.IndexSizeBytes = *o.IndexSizeBytes
558
	}
559
	if o.ItemCount != nil {
560
		result.ItemCount = *o.ItemCount
561
	}
562
563
	result.IndexStatus = IndexStatus(o.IndexStatus)
564
565
	result.KeySchema = newKeySchemaElements(o.KeySchema)
566
	result.Projection = newProjection(o.Projection)
567
	result.ProvisionedThroughput = newProvisionedThroughputDescription(o.ProvisionedThroughput)
568
	return result
569
}
570
571
type ItemCollectionMetrics struct {
0 ignored issues
show
introduced by
exported type ItemCollectionMetrics should have comment or be unexported
Loading history...
572
	ItemCollectionKey   map[string]AttributeValue `type:"map"`
573
	SizeEstimateRangeGB []float64                 `type:"list"`
574
}
575
576
func newItemCollectionMetrics(o SDK.ItemCollectionMetrics) ItemCollectionMetrics {
577
	result := ItemCollectionMetrics{}
578
579
	m := make(map[string]AttributeValue, len(o.ItemCollectionKey))
580
	for key, val := range o.ItemCollectionKey {
581
		m[key] = newAttributeValue(val)
582
	}
583
	result.ItemCollectionKey = m
584
585
	result.SizeEstimateRangeGB = o.SizeEstimateRangeGB
586
	return result
587
}
588
589
type KeysAndAttributes struct {
0 ignored issues
show
introduced by
exported type KeysAndAttributes should have comment or be unexported
Loading history...
590
	Keys []map[string]AttributeValue
591
592
	// optional
593
	AttributesToGet          []string
594
	ConsistentRead           bool
595
	ExpressionAttributeNames map[string]string
596
	ProjectionExpression     string
597
}
598
599
func newKeysAndAttributes(o SDK.KeysAndAttributes) KeysAndAttributes {
600
	result := KeysAndAttributes{}
601
602
	result.AttributesToGet = o.AttributesToGet
603
	result.ExpressionAttributeNames = o.ExpressionAttributeNames
604
605
	if o.ConsistentRead != nil {
606
		result.ConsistentRead = *o.ConsistentRead
607
	}
608
	if o.ProjectionExpression != nil {
609
		result.ProjectionExpression = *o.ProjectionExpression
610
	}
611
612
	if len(o.Keys) != 0 {
613
		list := make([]map[string]AttributeValue, len(o.Keys))
614
		for i, v := range o.Keys {
615
			list[i] = newAttributeValueMap(v)
616
		}
617
		result.Keys = list
618
	}
619
620
	return result
621
}
622
623
func (r KeysAndAttributes) ToSDK() SDK.KeysAndAttributes {
0 ignored issues
show
introduced by
exported method KeysAndAttributes.ToSDK should have comment or be unexported
Loading history...
624
	o := SDK.KeysAndAttributes{}
625
626
	if len(r.Keys) != 0 {
627
		list := make([]map[string]SDK.AttributeValue, len(r.Keys))
628
		for i, v := range r.Keys {
629
			m := make(map[string]SDK.AttributeValue, len(v))
630
			for key, val := range v {
631
				m[key] = val.ToSDK()
632
			}
633
			list[i] = m
634
		}
635
		o.Keys = list
636
	}
637
638
	if r.ConsistentRead {
639
		o.ConsistentRead = pointers.Bool(r.ConsistentRead)
640
	}
641
	if r.ProjectionExpression != "" {
642
		o.ProjectionExpression = pointers.String(r.ProjectionExpression)
643
	}
644
645
	o.AttributesToGet = r.AttributesToGet
646
	o.ExpressionAttributeNames = r.ExpressionAttributeNames
647
	return o
648
}
649
650
type KeySchemaElement struct {
0 ignored issues
show
introduced by
exported type KeySchemaElement should have comment or be unexported
Loading history...
651
	AttributeName string
652
	KeyType       KeyType
653
}
654
655
func newKeySchemaElements(list []SDK.KeySchemaElement) []KeySchemaElement {
656
	if len(list) == 0 {
657
		return nil
658
	}
659
660
	results := make([]KeySchemaElement, len(list))
661
	for i, v := range list {
662
		results[i] = newKeySchemaElement(v)
663
	}
664
	return results
665
}
666
667
func newKeySchemaElement(o SDK.KeySchemaElement) KeySchemaElement {
668
	result := KeySchemaElement{}
669
670
	if o.AttributeName != nil {
671
		result.AttributeName = *o.AttributeName
672
	}
673
674
	result.KeyType = KeyType(o.KeyType)
675
	return result
676
}
677
678
func (r KeySchemaElement) ToSDK() SDK.KeySchemaElement {
0 ignored issues
show
introduced by
exported method KeySchemaElement.ToSDK should have comment or be unexported
Loading history...
679
	o := SDK.KeySchemaElement{}
680
681
	if r.AttributeName != "" {
682
		o.AttributeName = pointers.String(r.AttributeName)
683
	}
684
	o.KeyType = SDK.KeyType(r.KeyType)
685
	return o
686
}
687
688
type LocalSecondaryIndex struct {
0 ignored issues
show
introduced by
exported type LocalSecondaryIndex should have comment or be unexported
Loading history...
689
	IndexName  string
690
	KeySchema  []KeySchemaElement
691
	Projection Projection
692
}
693
694
func (r LocalSecondaryIndex) ToSDK() SDK.LocalSecondaryIndex {
0 ignored issues
show
introduced by
exported method LocalSecondaryIndex.ToSDK should have comment or be unexported
Loading history...
695
	o := SDK.LocalSecondaryIndex{}
696
697
	if r.IndexName != "" {
698
		o.IndexName = pointers.String(r.IndexName)
699
	}
700
701
	if r.Projection.hasValue() {
702
		v := r.Projection.ToSDK()
703
		o.Projection = &v
704
	}
705
706
	if len(r.KeySchema) != 0 {
707
		list := make([]SDK.KeySchemaElement, len(r.KeySchema))
708
		for i, v := range r.KeySchema {
709
			list[i] = v.ToSDK()
710
		}
711
		o.KeySchema = list
712
	}
713
	return o
714
}
715
716
type LocalSecondaryIndexDescription struct {
0 ignored issues
show
introduced by
exported type LocalSecondaryIndexDescription should have comment or be unexported
Loading history...
717
	IndexARN       string
718
	IndexName      string
719
	IndexSizeBytes int64
720
	ItemCount      int64
721
	KeySchema      []KeySchemaElement
722
	Projection     Projection
723
}
724
725
func newLocalSecondaryIndexDescriptions(list []SDK.LocalSecondaryIndexDescription) []LocalSecondaryIndexDescription {
726
	if len(list) == 0 {
727
		return nil
728
	}
729
730
	result := make([]LocalSecondaryIndexDescription, len(list))
731
	for i, v := range list {
732
		result[i] = newLocalSecondaryIndexDescription(v)
733
	}
734
	return result
735
}
736
737
func newLocalSecondaryIndexDescription(o SDK.LocalSecondaryIndexDescription) LocalSecondaryIndexDescription {
738
	result := LocalSecondaryIndexDescription{}
739
740
	if o.IndexArn != nil {
741
		result.IndexARN = *o.IndexArn
742
	}
743
	if o.IndexName != nil {
744
		result.IndexName = *o.IndexName
745
	}
746
	if o.IndexSizeBytes != nil {
747
		result.IndexSizeBytes = *o.IndexSizeBytes
748
	}
749
	if o.ItemCount != nil {
750
		result.ItemCount = *o.ItemCount
751
	}
752
753
	result.KeySchema = newKeySchemaElements(o.KeySchema)
754
	result.Projection = newProjection(o.Projection)
755
	return result
756
}
757
758
type Projection struct {
0 ignored issues
show
introduced by
exported type Projection should have comment or be unexported
Loading history...
759
	NonKeyAttributes []string
760
	ProjectionType   ProjectionType
761
}
762
763
func newProjection(o *SDK.Projection) Projection {
764
	result := Projection{}
765
	if o == nil {
766
		return result
767
	}
768
769
	result.NonKeyAttributes = o.NonKeyAttributes
770
	result.ProjectionType = ProjectionType(o.ProjectionType)
771
	return result
772
}
773
774
func (r Projection) ToSDK() SDK.Projection {
0 ignored issues
show
introduced by
exported method Projection.ToSDK should have comment or be unexported
Loading history...
775
	o := SDK.Projection{}
776
	o.NonKeyAttributes = r.NonKeyAttributes
777
	o.ProjectionType = SDK.ProjectionType(r.ProjectionType)
778
	return o
779
}
780
781
func (r Projection) hasValue() bool {
782
	switch {
783
	case r.ProjectionType != "",
784
		len(r.NonKeyAttributes) != 0:
785
		return true
786
	}
787
	return false
788
}
789
790
type ProvisionedThroughput struct {
0 ignored issues
show
introduced by
exported type ProvisionedThroughput should have comment or be unexported
Loading history...
791
	ReadCapacityUnits  int64
792
	WriteCapacityUnits int64
793
}
794
795
func (r ProvisionedThroughput) ToSDK() SDK.ProvisionedThroughput {
0 ignored issues
show
introduced by
exported method ProvisionedThroughput.ToSDK should have comment or be unexported
Loading history...
796
	return SDK.ProvisionedThroughput{
797
		ReadCapacityUnits:  pointers.Long64(r.ReadCapacityUnits),
798
		WriteCapacityUnits: pointers.Long64(r.WriteCapacityUnits),
799
	}
800
}
801
802
func (r ProvisionedThroughput) hasValue() bool {
803
	switch {
804
	case r.ReadCapacityUnits != 0,
805
		r.WriteCapacityUnits != 0:
806
		return true
807
	}
808
	return false
809
}
810
811
type ProvisionedThroughputDescription struct {
0 ignored issues
show
introduced by
exported type ProvisionedThroughputDescription should have comment or be unexported
Loading history...
812
	LastDecreaseDateTime   time.Time
813
	LastIncreaseDateTime   time.Time
814
	NumberOfDecreasesToday int64
815
	ReadCapacityUnits      int64
816
	WriteCapacityUnits     int64
817
}
818
819
func newProvisionedThroughputDescription(o *SDK.ProvisionedThroughputDescription) ProvisionedThroughputDescription {
820
	result := ProvisionedThroughputDescription{}
821
	if o == nil {
822
		return result
823
	}
824
825
	if o.LastDecreaseDateTime != nil {
826
		result.LastDecreaseDateTime = *o.LastDecreaseDateTime
827
	}
828
	if o.LastIncreaseDateTime != nil {
829
		result.LastIncreaseDateTime = *o.LastIncreaseDateTime
830
	}
831
	if o.NumberOfDecreasesToday != nil {
832
		result.NumberOfDecreasesToday = *o.NumberOfDecreasesToday
833
	}
834
	if o.ReadCapacityUnits != nil {
835
		result.ReadCapacityUnits = *o.ReadCapacityUnits
836
	}
837
	if o.WriteCapacityUnits != nil {
838
		result.WriteCapacityUnits = *o.WriteCapacityUnits
839
	}
840
	return result
841
}
842
843
type ReplicaDescription struct {
0 ignored issues
show
introduced by
exported type ReplicaDescription should have comment or be unexported
Loading history...
844
	GlobalSecondaryIndexes       []ReplicaGlobalSecondaryIndexDescription
845
	KMSMasterKeyID               string
846
	RegionName                   string
847
	ReplicaStatus                ReplicaStatus
848
	ReplicaStatusDescription     string
849
	ReplicaStatusPercentProgress string
850
851
	ProvisionedThroughputOverrideRCU int64
852
}
853
854
func newReplicaDescriptions(list []SDK.ReplicaDescription) []ReplicaDescription {
855
	if len(list) == 0 {
856
		return nil
857
	}
858
859
	result := make([]ReplicaDescription, len(list))
860
	for i, v := range list {
861
		result[i] = newReplicaDescription(v)
862
	}
863
	return result
864
}
865
866
func newReplicaDescription(o SDK.ReplicaDescription) ReplicaDescription {
867
	result := ReplicaDescription{}
868
869
	if o.KMSMasterKeyId != nil {
870
		result.KMSMasterKeyID = *o.KMSMasterKeyId
871
	}
872
	if o.RegionName != nil {
873
		result.RegionName = *o.RegionName
874
	}
875
	if o.ReplicaStatusDescription != nil {
876
		result.ReplicaStatusDescription = *o.ReplicaStatusDescription
877
	}
878
	if o.ReplicaStatusPercentProgress != nil {
879
		result.ReplicaStatusPercentProgress = *o.ReplicaStatusPercentProgress
880
	}
881
882
	result.ReplicaStatus = ReplicaStatus(o.ReplicaStatus)
883
884
	result.GlobalSecondaryIndexes = newReplicaGlobalSecondaryIndexDescriptions(o.GlobalSecondaryIndexes)
885
	if v := o.ProvisionedThroughputOverride; v != nil {
886
		if v.ReadCapacityUnits != nil {
887
			result.ProvisionedThroughputOverrideRCU = *v.ReadCapacityUnits
888
		}
889
	}
890
	return result
891
}
892
893
type ReplicaGlobalSecondaryIndexDescription struct {
0 ignored issues
show
introduced by
exported type ReplicaGlobalSecondaryIndexDescription should have comment or be unexported
Loading history...
894
	IndexName                        string
895
	ProvisionedThroughputOverrideRCU int64
896
}
897
898
func newReplicaGlobalSecondaryIndexDescriptions(list []SDK.ReplicaGlobalSecondaryIndexDescription) []ReplicaGlobalSecondaryIndexDescription {
899
	if len(list) == 0 {
900
		return nil
901
	}
902
903
	result := make([]ReplicaGlobalSecondaryIndexDescription, len(list))
904
	for i, v := range list {
905
		result[i] = newReplicaGlobalSecondaryIndexDescription(v)
906
	}
907
	return result
908
}
909
910
func newReplicaGlobalSecondaryIndexDescription(o SDK.ReplicaGlobalSecondaryIndexDescription) ReplicaGlobalSecondaryIndexDescription {
911
	result := ReplicaGlobalSecondaryIndexDescription{}
912
913
	if o.IndexName != nil {
914
		result.IndexName = *o.IndexName
915
	}
916
	if v := o.ProvisionedThroughputOverride; v != nil {
917
		if v.ReadCapacityUnits != nil {
918
			result.ProvisionedThroughputOverrideRCU = *v.ReadCapacityUnits
919
		}
920
	}
921
	return result
922
}
923
924
type RestoreSummary struct {
0 ignored issues
show
introduced by
exported type RestoreSummary should have comment or be unexported
Loading history...
925
	RestoreDateTime   time.Time
926
	RestoreInProgress bool
927
928
	// optional
929
	SourceBackupARN string
930
	SourceTableARN  string
931
}
932
933
func newRestoreSummary(o *SDK.RestoreSummary) RestoreSummary {
934
	result := RestoreSummary{}
935
	if o == nil {
936
		return result
937
	}
938
939
	if o.RestoreDateTime != nil {
940
		result.RestoreDateTime = *o.RestoreDateTime
941
	}
942
	if o.RestoreInProgress != nil {
943
		result.RestoreInProgress = *o.RestoreInProgress
944
	}
945
	if o.SourceBackupArn != nil {
946
		result.SourceBackupARN = *o.SourceBackupArn
947
	}
948
	if o.SourceTableArn != nil {
949
		result.SourceTableARN = *o.SourceTableArn
950
	}
951
	return result
952
}
953
954
type SSEDescription struct {
0 ignored issues
show
introduced by
exported type SSEDescription should have comment or be unexported
Loading history...
955
	InaccessibleEncryptionDateTime time.Time
956
	KMSMasterKeyArn                string
957
	SSEType                        SSEType
958
	Status                         SSEStatus
959
}
960
961
func newSSEDescription(o *SDK.SSEDescription) SSEDescription {
962
	result := SSEDescription{}
963
	if o == nil {
964
		return result
965
	}
966
967
	if o.InaccessibleEncryptionDateTime != nil {
968
		result.InaccessibleEncryptionDateTime = *o.InaccessibleEncryptionDateTime
969
	}
970
	if o.KMSMasterKeyArn != nil {
971
		result.KMSMasterKeyArn = *o.KMSMasterKeyArn
972
	}
973
	result.SSEType = SSEType(o.SSEType)
974
	result.Status = SSEStatus(o.Status)
975
	return result
976
}
977
978
type SSESpecification struct {
0 ignored issues
show
introduced by
exported type SSESpecification should have comment or be unexported
Loading history...
979
	Enabled        bool
980
	KMSMasterKeyID string
981
	SSEType        SSEType
982
}
983
984
func (r SSESpecification) ToSDK() SDK.SSESpecification {
0 ignored issues
show
introduced by
exported method SSESpecification.ToSDK should have comment or be unexported
Loading history...
985
	o := SDK.SSESpecification{}
986
987
	if r.Enabled {
988
		o.Enabled = pointers.Bool(r.Enabled)
989
	}
990
	if r.KMSMasterKeyID != "" {
991
		o.KMSMasterKeyId = pointers.String(r.KMSMasterKeyID)
992
	}
993
	o.SSEType = SDK.SSEType(r.SSEType)
994
	return o
995
}
996
997
func (r SSESpecification) hasValue() bool {
998
	switch {
999
	case r.Enabled,
1000
		r.KMSMasterKeyID != "",
1001
		r.SSEType != "":
1002
		return true
1003
	}
1004
	return false
1005
}
1006
1007
type StreamSpecification struct {
0 ignored issues
show
introduced by
exported type StreamSpecification should have comment or be unexported
Loading history...
1008
	StreamEnabled bool
1009
1010
	// optional
1011
	StreamViewType StreamViewType
1012
}
1013
1014
func newStreamSpecification(o *SDK.StreamSpecification) StreamSpecification {
1015
	result := StreamSpecification{}
1016
	if o == nil {
1017
		return result
1018
	}
1019
1020
	if o.StreamEnabled != nil {
1021
		result.StreamEnabled = *o.StreamEnabled
1022
	}
1023
	result.StreamViewType = StreamViewType(o.StreamViewType)
1024
	return result
1025
}
1026
1027
func (r StreamSpecification) ToSDK() SDK.StreamSpecification {
0 ignored issues
show
introduced by
exported method StreamSpecification.ToSDK should have comment or be unexported
Loading history...
1028
	o := SDK.StreamSpecification{}
1029
1030
	if r.StreamEnabled {
1031
		o.StreamEnabled = pointers.Bool(r.StreamEnabled)
1032
	}
1033
1034
	o.StreamViewType = SDK.StreamViewType(r.StreamViewType)
1035
	return o
1036
}
1037
1038
func (r StreamSpecification) hasValue() bool {
1039
	switch {
1040
	case r.StreamEnabled,
1041
		r.StreamViewType != "":
1042
		return true
1043
	}
1044
	return false
1045
}
1046
1047
type TableDescription struct {
0 ignored issues
show
introduced by
exported type TableDescription should have comment or be unexported
Loading history...
1048
	ArchivalSummary        ArchivalSummary
1049
	AttributeDefinitions   []AttributeDefinition
1050
	BillingModeSummary     BillingModeSummary
1051
	CreationDateTime       time.Time
1052
	GlobalSecondaryIndexes []GlobalSecondaryIndexDescription
1053
	GlobalTableVersion     string
1054
	ItemCount              int64
1055
	KeySchema              []KeySchemaElement
1056
	LatestStreamARN        string
1057
	LatestStreamLabel      string
1058
	LocalSecondaryIndexes  []LocalSecondaryIndexDescription
1059
	ProvisionedThroughput  ProvisionedThroughputDescription
1060
	Replicas               []ReplicaDescription
1061
	RestoreSummary         RestoreSummary
1062
	SSEDescription         SSEDescription
1063
	StreamSpecification    StreamSpecification
1064
	TableARN               string
1065
	TableID                string
1066
	TableName              string
1067
	TableSizeBytes         int64
1068
	TableStatus            TableStatus
1069
}
1070
1071
func newTableDescription(o SDK.TableDescription) TableDescription {
1072
	result := TableDescription{}
1073
1074
	if o.CreationDateTime != nil {
1075
		result.CreationDateTime = *o.CreationDateTime
1076
	}
1077
	if o.GlobalTableVersion != nil {
1078
		result.GlobalTableVersion = *o.GlobalTableVersion
1079
	}
1080
	if o.ItemCount != nil {
1081
		result.ItemCount = *o.ItemCount
1082
	}
1083
	if o.LatestStreamArn != nil {
1084
		result.LatestStreamARN = *o.LatestStreamArn
1085
	}
1086
	if o.LatestStreamLabel != nil {
1087
		result.LatestStreamLabel = *o.LatestStreamLabel
1088
	}
1089
	if o.TableArn != nil {
1090
		result.TableARN = *o.TableArn
1091
	}
1092
	if o.TableId != nil {
1093
		result.TableID = *o.TableId
1094
	}
1095
	if o.TableName != nil {
1096
		result.TableName = *o.TableName
1097
	}
1098
	if o.TableSizeBytes != nil {
1099
		result.TableSizeBytes = *o.TableSizeBytes
1100
	}
1101
1102
	result.TableStatus = TableStatus(o.TableStatus)
1103
1104
	result.ArchivalSummary = newArchivalSummary(o.ArchivalSummary)
1105
	result.BillingModeSummary = newBillingModeSummary(o.BillingModeSummary)
1106
	result.ProvisionedThroughput = newProvisionedThroughputDescription(o.ProvisionedThroughput)
1107
	result.RestoreSummary = newRestoreSummary(o.RestoreSummary)
1108
	result.SSEDescription = newSSEDescription(o.SSEDescription)
1109
	result.StreamSpecification = newStreamSpecification(o.StreamSpecification)
1110
1111
	result.AttributeDefinitions = newAttributeDefinitions(o.AttributeDefinitions)
1112
	result.GlobalSecondaryIndexes = newGlobalSecondaryIndexDescriptions(o.GlobalSecondaryIndexes)
1113
	result.LocalSecondaryIndexes = newLocalSecondaryIndexDescriptions(o.LocalSecondaryIndexes)
1114
	result.KeySchema = newKeySchemaElements(o.KeySchema)
1115
	result.Replicas = newReplicaDescriptions(o.Replicas)
1116
	return result
1117
}
1118
1119
type Tag struct {
0 ignored issues
show
introduced by
exported type Tag should have comment or be unexported
Loading history...
1120
	Key   string
1121
	Value string
1122
}
1123
1124
func (r Tag) ToSDK() SDK.Tag {
0 ignored issues
show
introduced by
exported method Tag.ToSDK should have comment or be unexported
Loading history...
1125
	o := SDK.Tag{}
1126
1127
	if r.Key != "" {
1128
		o.Key = pointers.String(r.Key)
1129
	}
1130
	if r.Value != "" {
1131
		o.Value = pointers.String(r.Value)
1132
	}
1133
	return o
1134
}
1135
1136
type WriteRequest struct {
0 ignored issues
show
introduced by
exported type WriteRequest should have comment or be unexported
Loading history...
1137
	DeleteKeys map[string]AttributeValue
1138
	PutItems   map[string]AttributeValue
1139
}
1140
1141
func newWriteRequest(o SDK.WriteRequest) WriteRequest {
1142
	result := WriteRequest{
1143
		DeleteKeys: make(map[string]AttributeValue),
1144
		PutItems:   make(map[string]AttributeValue),
1145
	}
1146
1147
	if o.DeleteRequest != nil {
1148
		m := make(map[string]AttributeValue, len(o.DeleteRequest.Key))
1149
		for key, val := range o.DeleteRequest.Key {
1150
			m[key] = newAttributeValue(val)
1151
		}
1152
		result.DeleteKeys = m
1153
	}
1154
1155
	if o.PutRequest != nil {
1156
		m := make(map[string]AttributeValue, len(o.PutRequest.Item))
1157
		for key, val := range o.PutRequest.Item {
1158
			m[key] = newAttributeValue(val)
1159
		}
1160
		result.DeleteKeys = m
1161
	}
1162
1163
	return result
1164
}
1165
1166
func (r WriteRequest) ToSDK() SDK.WriteRequest {
0 ignored issues
show
introduced by
exported method WriteRequest.ToSDK should have comment or be unexported
Loading history...
1167
	o := SDK.WriteRequest{}
1168
1169
	if len(r.DeleteKeys) != 0 {
1170
		m := make(map[string]SDK.AttributeValue, len(r.DeleteKeys))
1171
		for key, val := range r.DeleteKeys {
1172
			m[key] = val.ToSDK()
1173
		}
1174
		o.DeleteRequest = &SDK.DeleteRequest{
1175
			Key: m,
1176
		}
1177
	}
1178
1179
	if len(r.PutItems) != 0 {
1180
		m := make(map[string]SDK.AttributeValue, len(r.PutItems))
1181
		for key, val := range r.PutItems {
1182
			m[key] = val.ToSDK()
1183
		}
1184
		o.PutRequest = &SDK.PutRequest{
1185
			Item: m,
1186
		}
1187
	}
1188
1189
	return o
1190
}
1191