replace datatype.Kind() with Type()

This commit is contained in:
Adrien Marquès 2020-03-28 19:11:23 +01:00
parent 8cfa2235d6
commit 76cc2f5279
Signed by: xdrm-brackets
GPG Key ID: D75243CA236D825E
9 changed files with 28 additions and 28 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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