equal
deleted
inserted
replaced
52 return errors.New("cannot add shadow to another shadow key") |
52 return errors.New("cannot add shadow to another shadow key") |
53 } else if k.isAutoIncrement || k.isBooleanType { |
53 } else if k.isAutoIncrement || k.isBooleanType { |
54 return errors.New("cannot add shadow to auto-increment or boolean key") |
54 return errors.New("cannot add shadow to auto-increment or boolean key") |
55 } |
55 } |
56 |
56 |
57 // Deduplicate shadows based on their values. |
57 if !k.s.f.options.AllowDuplicateShadowValues { |
58 if k.value == val { |
58 // Deduplicate shadows based on their values. |
59 return nil |
59 if k.value == val { |
60 } |
|
61 for i := range k.shadows { |
|
62 if k.shadows[i].value == val { |
|
63 return nil |
60 return nil |
|
61 } |
|
62 for i := range k.shadows { |
|
63 if k.shadows[i].value == val { |
|
64 return nil |
|
65 } |
64 } |
66 } |
65 } |
67 } |
66 |
68 |
67 shadow := newKey(k.s, k.name, val) |
69 shadow := newKey(k.s, k.name, val) |
68 shadow.isShadow = true |
70 shadow.isShadow = true |
106 // Value returns raw value of key for performance purpose. |
108 // Value returns raw value of key for performance purpose. |
107 func (k *Key) Value() string { |
109 func (k *Key) Value() string { |
108 return k.value |
110 return k.value |
109 } |
111 } |
110 |
112 |
111 // ValueWithShadows returns raw values of key and its shadows if any. |
113 // ValueWithShadows returns raw values of key and its shadows if any. Shadow |
|
114 // keys with empty values are ignored from the returned list. |
112 func (k *Key) ValueWithShadows() []string { |
115 func (k *Key) ValueWithShadows() []string { |
113 if len(k.shadows) == 0 { |
116 if len(k.shadows) == 0 { |
|
117 if k.value == "" { |
|
118 return []string{} |
|
119 } |
114 return []string{k.value} |
120 return []string{k.value} |
115 } |
121 } |
116 vals := make([]string, len(k.shadows)+1) |
122 |
117 vals[0] = k.value |
123 vals := make([]string, 0, len(k.shadows)+1) |
118 for i := range k.shadows { |
124 if k.value != "" { |
119 vals[i+1] = k.shadows[i].value |
125 vals = append(vals, k.value) |
|
126 } |
|
127 for _, s := range k.shadows { |
|
128 if s.value != "" { |
|
129 vals = append(vals, s.value) |
|
130 } |
120 } |
131 } |
121 return vals |
132 return vals |
122 } |
133 } |
123 |
134 |
124 // NestedValues returns nested values stored in the key. |
135 // NestedValues returns nested values stored in the key. |
779 } |
790 } |
780 } |
791 } |
781 return vals, err |
792 return vals, err |
782 } |
793 } |
783 |
794 |
784 |
|
785 type Parser func(str string) (interface{}, error) |
795 type Parser func(str string) (interface{}, error) |
786 |
|
787 |
796 |
788 // parseTimesFormat transforms strings to times in given format. |
797 // parseTimesFormat transforms strings to times in given format. |
789 func (k *Key) parseTimesFormat(format string, strs []string, addInvalid, returnOnInvalid bool) ([]time.Time, error) { |
798 func (k *Key) parseTimesFormat(format string, strs []string, addInvalid, returnOnInvalid bool) ([]time.Time, error) { |
790 vals := make([]time.Time, 0, len(strs)) |
799 vals := make([]time.Time, 0, len(strs)) |
791 parser := func(str string) (interface{}, error) { |
800 parser := func(str string) (interface{}, error) { |
798 vals = append(vals, val.(time.Time)) |
807 vals = append(vals, val.(time.Time)) |
799 } |
808 } |
800 } |
809 } |
801 return vals, err |
810 return vals, err |
802 } |
811 } |
803 |
|
804 |
812 |
805 // doParse transforms strings to different types |
813 // doParse transforms strings to different types |
806 func (k *Key) doParse(strs []string, addInvalid, returnOnInvalid bool, parser Parser) ([]interface{}, error) { |
814 func (k *Key) doParse(strs []string, addInvalid, returnOnInvalid bool, parser Parser) ([]interface{}, error) { |
807 vals := make([]interface{}, 0, len(strs)) |
815 vals := make([]interface{}, 0, len(strs)) |
808 for _, str := range strs { |
816 for _, str := range strs { |