Skip to content

Commit

Permalink
Create a method to use json.RawMessage as input instead of io.Reader
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoholiveira committed Aug 23, 2019
1 parent 1a172a1 commit 4a3a128
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions jsonlogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,3 +700,35 @@ func Apply(rule, data io.Reader, result io.Writer) error {

return nil
}

func ApplyRaw(rule, data json.RawMessage) (json.RawMessage, error) {
var _rule interface{}
var _data interface{}

err := json.Unmarshal(rule, &_rule)
if err != nil {
return nil, err
}

err = json.Unmarshal(data, &_data)
if err != nil {
return nil, err
}

var result interface{}

if isMap(_rule) {
result = apply(_rule, _data)
} else {
result = _rule
}

var output json.RawMessage

output, err = json.Marshal(&result)
if err != nil {
return nil, err
}

return output, nil
}

0 comments on commit 4a3a128

Please sign in to comment.