-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkey.go
104 lines (87 loc) · 2.08 KB
/
key.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package djoemo
type key struct {
tableName string
hashKeyName *string
rangeKeyName *string
hashKey interface{}
rangeKey interface{}
}
// Key factory method to create struct that implements key interface
func Key() *key {
return &key{}
}
// WithTableName set djoemo key table name
func (k *key) WithTableName(tableName string) *key {
k.tableName = tableName
return k
}
// WithHashKeyName set djoemo key hash key name
func (k *key) WithHashKeyName(hashKeyName string) *key {
k.hashKeyName = &hashKeyName
return k
}
// WithRangeKeyName set djoemo key range key name
func (k *key) WithRangeKeyName(rangeKeyName string) *key {
k.rangeKeyName = &rangeKeyName
return k
}
// WithHashKey set djoemo key hash key value
func (k *key) WithHashKey(hashKey interface{}) *key {
k.hashKey = hashKey
return k
}
// WithRangeKey set djoemo key range key value
func (k *key) WithRangeKey(rangeKey interface{}) *key {
k.rangeKey = rangeKey
return k
}
// TableName returns the djoemo table name
func (k *key) TableName() string {
return k.tableName
}
// HashKeyName returns the name of hash key if exists
func (k *key) HashKeyName() *string {
return k.hashKeyName
}
// RangeKeyName returns the name of range key if exists
func (k *key) RangeKeyName() *string {
return k.rangeKeyName
}
// HashKey returns the hash key value
func (k *key) HashKey() interface{} {
return k.hashKey
}
// HashKey returns the range key value
func (k *key) RangeKey() interface{} {
return k.rangeKey
}
func isValidKey(key KeyInterface) error {
if err := isValidTableName(key); err != nil {
return err
}
if err := isValidHashKeyName(key); err != nil {
return err
}
if err := isValidHashKey(key); err != nil {
return err
}
return nil
}
func isValidTableName(key KeyInterface) error {
if key.TableName() == "" {
return ErrInvalidTableName
}
return nil
}
func isValidHashKeyName(key KeyInterface) error {
if key.HashKeyName() == nil {
return ErrInvalidHashKeyName
}
return nil
}
func isValidHashKey(key KeyInterface) error {
if key.HashKey() == nil {
return ErrInvalidHashKeyValue
}
return nil
}