3
0

Improvments on expressions, gw tests

This commit is contained in:
Denis Arh
2021-03-30 14:39:00 +02:00
parent 723c361171
commit 597c18fd16
8 changed files with 319 additions and 161 deletions
+6 -3
View File
@@ -23,6 +23,7 @@ var _ = context.Background
var _ = fmt.Errorf
{{ range $exprType, $def := .Types }}
{{ if not $def.CustomType }}
// {{ $exprType }} is an expression type, wrapper for {{ $def.As }} type
type {{ $exprType }} struct{ value {{ $def.As }} }
@@ -81,12 +82,14 @@ func (t {{ $exprType }}) SelectGVal(ctx context.Context, k string) (interface{},
}
{{ end }}
{{ if not $def.CustomSelector }}
// Select is field accessor for {{ $def.As }}
//
// Similar to SelectGVal but returns typed values
func (t {{ $exprType }}) Select(k string) (TypedValue, error) {
return {{ unexport $exprType "TypedValueSelector" }}(t.value, k)
}
{{ end }}
func (t {{ $exprType }}) Has(k string) bool {
switch k {
@@ -150,7 +153,7 @@ func {{ $def.AssignerFn }}(res {{ $def.As }}, k string, val interface{}) (error)
return fmt.Errorf("unknown field '%s'", k)
}
{{ end }}
{{ end }}
{{ end }}
{{ end }} {{/* if $def.Struct */}}
{{ end }} {{/* if not $def.CustomType */}}
{{ end }} {{/* types loop */}}
+2
View File
@@ -28,7 +28,9 @@ type (
AssignerFn string `yaml:"assignerFn"`
BuiltInCastFn bool
BuiltInAssignerFn bool
CustomType bool `yaml:"customType"`
CustomGValSelector bool `yaml:"customGValSelector"`
CustomSelector bool `yaml:"customSelector"`
CustomFieldAssigner bool `yaml:"customFieldAssigner"`
Struct []*exprTypeStructDef