diff --git a/datatype/builtin/any.go b/datatype/builtin/any.go index c7af7e9..e12dd10 100644 --- a/datatype/builtin/any.go +++ b/datatype/builtin/any.go @@ -6,7 +6,7 @@ import "git.xdrm.io/go/aicra/datatype" type AnyDataType struct{} // Build returns the validator -func (AnyDataType) Build(typeName string) datatype.Validator { +func (AnyDataType) Build(typeName string, registry ...datatype.T) datatype.Validator { // nothing if type not handled if typeName != "any" { return nil diff --git a/datatype/builtin/bool.go b/datatype/builtin/bool.go index 2b0240b..1d5e225 100644 --- a/datatype/builtin/bool.go +++ b/datatype/builtin/bool.go @@ -6,7 +6,7 @@ import "git.xdrm.io/go/aicra/datatype" type BoolDataType struct{} // Build returns the validator -func (BoolDataType) Build(typeName string) datatype.Validator { +func (BoolDataType) Build(typeName string, registry ...datatype.T) datatype.Validator { // nothing if type not handled if typeName != "bool" { return nil diff --git a/datatype/builtin/float.go b/datatype/builtin/float.go index 6f64e58..d2f3204 100644 --- a/datatype/builtin/float.go +++ b/datatype/builtin/float.go @@ -10,7 +10,7 @@ import ( type FloatDataType struct{} // Build returns the validator -func (FloatDataType) Build(typeName string) datatype.Validator { +func (FloatDataType) Build(typeName string, registry ...datatype.T) datatype.Validator { // nothing if type not handled if typeName != "float64" && typeName != "float" { return nil diff --git a/datatype/builtin/int.go b/datatype/builtin/int.go index 453c4f1..7dfdbf9 100644 --- a/datatype/builtin/int.go +++ b/datatype/builtin/int.go @@ -11,7 +11,7 @@ import ( type IntDataType struct{} // Build returns the validator -func (IntDataType) Build(typeName string) datatype.Validator { +func (IntDataType) Build(typeName string, registry ...datatype.T) datatype.Validator { // nothing if type not handled if typeName != "int" { return nil diff --git a/datatype/builtin/string.go b/datatype/builtin/string.go index afee83a..1a94b82 100644 --- a/datatype/builtin/string.go +++ b/datatype/builtin/string.go @@ -15,7 +15,7 @@ type StringDataType struct{} // Build returns the validator. // availables type names are : `string`, `string(length)` and `string(minLength, maxLength)`. -func (s StringDataType) Build(typeName string) datatype.Validator { +func (s StringDataType) Build(typeName string, registry ...datatype.T) datatype.Validator { simple := typeName == "string" fixedLengthMatches := fixedLengthRegex.FindStringSubmatch(typeName) variableLengthMatches := variableLengthRegex.FindStringSubmatch(typeName) diff --git a/datatype/builtin/uint.go b/datatype/builtin/uint.go index 3f5bd76..53f71de 100644 --- a/datatype/builtin/uint.go +++ b/datatype/builtin/uint.go @@ -11,7 +11,7 @@ import ( type UintDataType struct{} // Build returns the validator -func (UintDataType) Build(typeName string) datatype.Validator { +func (UintDataType) Build(typeName string, registry ...datatype.T) datatype.Validator { // nothing if type not handled if typeName != "uint" { return nil diff --git a/datatype/types.go b/datatype/types.go index ad4be63..fe529f1 100644 --- a/datatype/types.go +++ b/datatype/types.go @@ -4,9 +4,9 @@ package datatype // and casts the value into a compatible type type Validator func(value interface{}) (cast interface{}, valid bool) -// T builds a T from the type definition (from the -// configuration field "type") and returns NIL if the type -// definition does not match this T +// T builds a T from the type definition (from the configuration field "type") and returns NIL if the type +// definition does not match this T ; the registry is passed for recursive datatypes (e.g. slices, structs, etc) +// to be able to access other datatypes type T interface { - Build(typeDefinition string) Validator + Build(typeDefinition string, registry ...T) Validator } diff --git a/internal/config/parameter.go b/internal/config/parameter.go index af08e49..9dc43fa 100644 --- a/internal/config/parameter.go +++ b/internal/config/parameter.go @@ -26,7 +26,7 @@ func (param *Parameter) checkAndFormat() error { // assigns the first matching data type from the type definition func (param *Parameter) assignDataType(types []datatype.T) bool { for _, dtype := range types { - param.Validator = dtype.Build(param.Type) + param.Validator = dtype.Build(param.Type, types...) if param.Validator != nil { return true }