-
Notifications
You must be signed in to change notification settings - Fork 14
/
helpers.go
76 lines (66 loc) · 1.8 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package dynago
import (
"strings"
)
type expressionAttributes struct {
ExpressionAttributeValues Document `json:",omitempty"`
ExpressionAttributeNames map[string]string `json:",omitempty"`
}
// Helper for a variety of endpoint types to build a params dictionary.
func (e *expressionAttributes) paramHelper(key string, value interface{}) {
e.assignParams([]Param{{key, value}})
}
// Helper to build multi-params dictionary
func (e *expressionAttributes) paramsHelper(params []Params) {
if len(params) == 0 {
return
}
output := make([]Param, 0, len(params))
for _, p := range params {
output = append(output, p.AsParams()...)
}
e.assignParams(output)
}
func (e *expressionAttributes) assignParams(params []Param) {
var copyValues, copyNames bool
for _, p := range params {
if strings.HasPrefix(p.Key, "#") {
if !copyNames {
copyNames = true
eaNameCopy(&e.ExpressionAttributeNames, 1)
}
e.ExpressionAttributeNames[p.Key] = p.Value.(string)
} else {
if !copyValues {
copyValues = true
paramCopy(&e.ExpressionAttributeValues, len(params))
}
e.ExpressionAttributeValues[p.Key] = p.Value
}
}
}
func paramCopy(doc *Document, extendBy int) Document {
params := make(Document, len(*doc)+extendBy)
if *doc != nil {
for k, v := range *doc {
params[k] = v
}
}
*doc = params
return params
}
func eaNameCopy(doc *map[string]string, extendBy int) {
names := make(map[string]string, len(*doc)+extendBy)
for k, v := range *doc {
names[k] = v
}
*doc = names
}
/*
Set the debug mode.
This is a set of bit-flags you can use to set up how much debugging dynago uses:
dynago.Debug = dynago.DebugRequests | dynago.DebugResponses
*/
var Debug DebugFlags
// Set the target of debug. Must be set for debug to be used.
var DebugFunc func(format string, v ...interface{})