Skip to content

Commit

Permalink
1. convert object, param and array from []bytes avoid unnecessary con…
Browse files Browse the repository at this point in the history
…version (#228)

2. Avoid to create duplicate scope
  • Loading branch information
lixingwang authored Oct 28, 2020
1 parent 202a27f commit d02ea62
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 27 additions & 0 deletions data/coerce/compound.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ func ToParams(val interface{}) (map[string]string, error) {
switch t := val.(type) {
case map[string]string:
return t, nil
case []byte:
var m map[string]string
if len(t) > 0 {
err := json.Unmarshal(t, &m)
if err != nil {
return nil, fmt.Errorf("unable to coerce %#v to params", val)
}
}
return m, nil
case string:
m := make(map[string]string)
if t != "" {
Expand Down Expand Up @@ -109,6 +118,15 @@ func ToObject(val interface{}) (map[string]interface{}, error) {
ret[key] = value
}
return ret, nil
case []byte:
var m map[string]interface{}
if len(t) > 0 {
err := json.Unmarshal(t, &m)
if err != nil {
return nil, fmt.Errorf("unable to coerce %#v to map[string]interface{}", val)
}
}
return m, nil
case string:
m := make(map[string]interface{})
if t != "" {
Expand Down Expand Up @@ -145,6 +163,15 @@ func ToArray(val interface{}) ([]interface{}, error) {
a = append(a, v)
}
return a, nil
case []byte:
a := make([]interface{}, 0)
if len(a) > 0 {
err := json.Unmarshal(t, &a)
if err != nil {
a = append(a, t)
}
}
return a, nil
case string:
a := make([]interface{}, 0)
if t != "" {
Expand Down
4 changes: 1 addition & 3 deletions trigger/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ func (h *handlerImpl) Handle(ctx context.Context, triggerData interface{}) (resu
var inputMap map[string]interface{}

if act.actionInputMapper != nil {
inScope := data.NewSimpleScope(triggerValues, nil)

inputMap, err = act.actionInputMapper.Apply(inScope)
inputMap, err = act.actionInputMapper.Apply(scope)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d02ea62

Please sign in to comment.