From 76cc2f52796b2a9fdb4af1a2d9f80d764bb804fb Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 28 Mar 2020 19:11:23 +0100 Subject: [PATCH] replace datatype.Kind() with Type() --- datatype/builtin/any.go | 6 +++--- datatype/builtin/bool.go | 6 +++--- datatype/builtin/float.go | 6 +++--- datatype/builtin/int.go | 6 +++--- datatype/builtin/string.go | 6 +++--- datatype/builtin/uint.go | 6 +++--- datatype/types.go | 2 +- internal/config/service.go | 2 +- internal/config/types.go | 16 ++++++++-------- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/datatype/builtin/any.go b/datatype/builtin/any.go index d96b26d..e1139b0 100644 --- a/datatype/builtin/any.go +++ b/datatype/builtin/any.go @@ -9,9 +9,9 @@ import ( // AnyDataType is what its name tells type AnyDataType struct{} -// Kind returns the kind of data -func (AnyDataType) Kind() reflect.Kind { - return reflect.Interface +// Type returns the type of data +func (AnyDataType) Type() reflect.Type { + return reflect.TypeOf(interface{}(nil)) } // Build returns the validator diff --git a/datatype/builtin/bool.go b/datatype/builtin/bool.go index 112158c..4d95547 100644 --- a/datatype/builtin/bool.go +++ b/datatype/builtin/bool.go @@ -9,9 +9,9 @@ import ( // BoolDataType is what its name tells type BoolDataType struct{} -// Kind returns the kind of data -func (BoolDataType) Kind() reflect.Kind { - return reflect.Bool +// Type returns the type of data +func (BoolDataType) Type() reflect.Type { + return reflect.TypeOf(true) } // Build returns the validator diff --git a/datatype/builtin/float.go b/datatype/builtin/float.go index 3eb4c23..5016f10 100644 --- a/datatype/builtin/float.go +++ b/datatype/builtin/float.go @@ -10,9 +10,9 @@ import ( // FloatDataType is what its name tells type FloatDataType struct{} -// Kind returns the kind of data -func (FloatDataType) Kind() reflect.Kind { - return reflect.Float64 +// Type returns the type of data +func (FloatDataType) Type() reflect.Type { + return reflect.TypeOf(float64(0)) } // Build returns the validator diff --git a/datatype/builtin/int.go b/datatype/builtin/int.go index 6559127..36b1038 100644 --- a/datatype/builtin/int.go +++ b/datatype/builtin/int.go @@ -11,9 +11,9 @@ import ( // IntDataType is what its name tells type IntDataType struct{} -// Kind returns the kind of data -func (IntDataType) Kind() reflect.Kind { - return reflect.Int +// Type returns the type of data +func (IntDataType) Type() reflect.Type { + return reflect.TypeOf(int(0)) } // Build returns the validator diff --git a/datatype/builtin/string.go b/datatype/builtin/string.go index b09b184..02be6ae 100644 --- a/datatype/builtin/string.go +++ b/datatype/builtin/string.go @@ -14,9 +14,9 @@ var variableLengthRegex = regexp.MustCompile(`^string\((\d+), ?(\d+)\)$`) // StringDataType is what its name tells type StringDataType struct{} -// Kind returns the kind of data -func (StringDataType) Kind() reflect.Kind { - return reflect.String +// Type returns the type of data +func (StringDataType) Type() reflect.Type { + return reflect.TypeOf(string("")) } // Build returns the validator. diff --git a/datatype/builtin/uint.go b/datatype/builtin/uint.go index d88fb5e..e59d2c1 100644 --- a/datatype/builtin/uint.go +++ b/datatype/builtin/uint.go @@ -11,9 +11,9 @@ import ( // UintDataType is what its name tells type UintDataType struct{} -// Kind returns the kind of data -func (UintDataType) Kind() reflect.Kind { - return reflect.Uint +// Type returns the type of data +func (UintDataType) Type() reflect.Type { + return reflect.TypeOf(uint(0)) } // Build returns the validator diff --git a/datatype/types.go b/datatype/types.go index a4761bb..c258b2f 100644 --- a/datatype/types.go +++ b/datatype/types.go @@ -10,6 +10,6 @@ type Validator func(value interface{}) (cast interface{}, valid bool) // 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 { - Kind() reflect.Kind + Type() reflect.Type Build(typeDefinition string, registry ...T) Validator } diff --git a/internal/config/service.go b/internal/config/service.go index d65251d..7c20724 100644 --- a/internal/config/service.go +++ b/internal/config/service.go @@ -238,7 +238,7 @@ func (svc *Service) validateInput(types []datatype.T) error { param.Validator = dtype.Build(param.Type, types...) if param.Validator != nil { datatypeFound = true - param.Kind = dtype.Kind() + param.ExtractType = dtype.Type() break } } diff --git a/internal/config/types.go b/internal/config/types.go index c3cc6f8..783959a 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -22,12 +22,12 @@ type Server struct { // Service represents a service definition (from api.json) type Service struct { - Method string `json:"method"` - Pattern string `json:"path"` - Scope [][]string `json:"scope"` - Description string `json:"info"` - Input map[string]*Parameter `json:"in"` - // Output map[string]*Parameter `json:"out"` + Method string `json:"method"` + Pattern string `json:"path"` + Scope [][]string `json:"scope"` + Description string `json:"info"` + Input map[string]*Parameter `json:"in"` + Output map[string]interface{} `json:"out"` // references to url parameters // format: '/uri/{param}' @@ -46,8 +46,8 @@ type Parameter struct { Description string `json:"info"` Type string `json:"type"` Rename string `json:"name,omitempty"` - // Kind of data the datatype returns - Kind reflect.Kind + // ExtractType is the type of data the datatype returns + ExtractType reflect.Type // Optional is set to true when the type is prefixed with '?' Optional bool