~humaid/workflow-engine unlisted

651fe2a4db6f865310769bab6cbf26f59a809d21 — Humaid AlQassimi 7 months ago 7aeb463 master
workflows: Add JSONPath function in scripting environment
3 files changed, 15 insertions(+), 0 deletions(-)

M go.mod
M go.sum
M workflows.go
M go.mod => go.mod +1 -0
@@ 25,6 25,7 @@ require (
	github.com/oklog/ulid/v2 v2.0.2
	github.com/smartystreets/assertions v1.1.0 // indirect
	github.com/smartystreets/goconvey v1.6.4
	github.com/spyzhov/ajson v0.2.3
	golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd // indirect
	golang.org/x/sys v0.0.0-20200513112337-417ce2331b5c // indirect
	gopkg.in/macaron.v1 v1.3.8

M go.sum => go.sum +2 -0
@@ 212,6 212,8 @@ github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:X
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/spyzhov/ajson v0.2.3 h1:6V2jH45co73LWOlilkwJ0+YR9d2TViu5K8n35lE+nMU=
github.com/spyzhov/ajson v0.2.3/go.mod h1:63V+CGM6f1Bu/p4nLIN8885ojBdt88TbLoSFzyqMuVA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=

M workflows.go => workflows.go +12 -0
@@ 10,6 10,7 @@ import (
	"time"

	"github.com/antonmedv/expr"
	"github.com/spyzhov/ajson"
	"xorm.io/xorm"

	"git.sr.ht/~humaid/workflow-engine/utils"


@@ 251,6 252,17 @@ func (e *Engine) getExpressions(tx *xorm.Session) map[string]interface{} {
		"since": func(t time.Time) int64 {
			return int64(time.Since(t))
		},
		"json": func(data string, path string) *ajson.Node {
			root, err := ajson.Unmarshal([]byte(data))
			if err != nil {
				panic(err)
			}
			result, err := ajson.Eval(root, path)
			if err != nil {
				panic(err)
			}
			return result
		},
	}
	return exprEnv
}