Rework/simplify expr.Vars handling

This commit is contained in:
Denis Arh
2021-04-01 21:10:51 +02:00
parent fc331cc388
commit fdf916b7f9
30 changed files with 436 additions and 324 deletions
+11 -9
View File
@@ -147,25 +147,27 @@ func (res {{ camelCase .ResourceIdent "base" }}) Encode() (args map[string][]byt
}
// Encode internal data to be passed as event params & arguments to workflow
func (res {{ camelCase .ResourceIdent "base" }}) EncodeVars() (vars *expr.Vars, err error) {
func (res {{ camelCase .ResourceIdent "base" }}) EncodeVars() (out *expr.Vars, err error) {
{{- if $r.Properties }}
var (
rvars = expr.RVars{}
)
out = &expr.Vars{}
var v expr.TypedValue
{{ range $r.Properties }}
{{- if .ExprType }}
if rvars[{{ printf "%q" .Name }}], err = automation.{{ export "new" .ExprType }}(res.{{ .Name }}); err != nil {
return nil, err
if v, err = automation.{{ export "new" .ExprType }}(res.{{ .Name }}); err == nil {
err = out.Set({{ printf "%q" .Name }},v)
}
if err != nil {
return
}
{{- else }}
// Could not found expression-type counterpart for {{ .Type }}
{{- end }}
{{ end }}
return rvars.Vars(), err
{{ else }}
return
{{ end -}}
_ = v
return
}
// Decode return values from Corredor script into struct props