Extend set/omit expr function
It updates 1st parameter of set expr function from merger type to interface, so It will accept constant values, also extend set/omit usage for ComposeRecordValues.
This commit is contained in:
+14
-1
@@ -64,7 +64,20 @@ func ResolveTypes(rt resolvableType, resolver func(typ string) Type) error {
|
||||
return rt.ResolveTypes(resolver)
|
||||
}
|
||||
|
||||
func set(m merger, key string, val interface{}) (out TypedValue, err error) {
|
||||
func set(i interface{}, key string, val interface{}) (out TypedValue, err error) {
|
||||
m, ok := i.(merger)
|
||||
if !ok {
|
||||
i, err = Typify(i)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
m, ok = i.(merger)
|
||||
if !ok {
|
||||
return out, fmt.Errorf("cannot set on unexpected type: %T", i)
|
||||
}
|
||||
}
|
||||
|
||||
out, err = m.Merge()
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
+4
-4
@@ -75,7 +75,7 @@ func (t *Vars) ResolveTypes(res func(typ string) Type) (err error) {
|
||||
}
|
||||
|
||||
// Merge combines the given Vars(es) into Vars
|
||||
// NOTE: It will return CLONE of the original Vars, if its called without any parameters
|
||||
// NOTE: It will return CLONE of the original Vars, if it's called without any parameters
|
||||
func (t *Vars) Merge(nn ...Iterator) (out TypedValue, err error) {
|
||||
return t.MustMerge(nn...), nil
|
||||
}
|
||||
@@ -336,7 +336,7 @@ func (t *Vars) Each(fn func(k string, v TypedValue) error) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Set set/update the specific key value in KV
|
||||
// Set or update the specific key value in Vars
|
||||
func (t *Vars) Set(k string, v interface{}) (err error) {
|
||||
t.mux.RLock()
|
||||
defer t.mux.RUnlock()
|
||||
@@ -485,7 +485,7 @@ func CastToVars(val interface{}) (out map[string]TypedValue, err error) {
|
||||
return nil, fmt.Errorf("unable to cast type %T to %T", val, out)
|
||||
}
|
||||
|
||||
// Filter take keys returns KV with only those key value pair
|
||||
// Filter take keys returns Vars with only those key value pair
|
||||
func (t *Vars) Filter(keys ...string) (out TypedValue, err error) {
|
||||
t.mux.RLock()
|
||||
defer t.mux.RUnlock()
|
||||
@@ -505,7 +505,7 @@ func (t *Vars) Filter(keys ...string) (out TypedValue, err error) {
|
||||
return vars, nil
|
||||
}
|
||||
|
||||
// Delete take keys returns KV without those key value pair
|
||||
// Delete take keys returns Vars without those key value pair
|
||||
func (t *Vars) Delete(keys ...string) (out TypedValue, err error) {
|
||||
t.mux.RLock()
|
||||
defer t.mux.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user