replace datatype.Kind() with Type()
This commit is contained in:
parent
8cfa2235d6
commit
76cc2f5279
|
@ -9,9 +9,9 @@ import (
|
||||||
// AnyDataType is what its name tells
|
// AnyDataType is what its name tells
|
||||||
type AnyDataType struct{}
|
type AnyDataType struct{}
|
||||||
|
|
||||||
// Kind returns the kind of data
|
// Type returns the type of data
|
||||||
func (AnyDataType) Kind() reflect.Kind {
|
func (AnyDataType) Type() reflect.Type {
|
||||||
return reflect.Interface
|
return reflect.TypeOf(interface{}(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build returns the validator
|
// Build returns the validator
|
||||||
|
|
|
@ -9,9 +9,9 @@ import (
|
||||||
// BoolDataType is what its name tells
|
// BoolDataType is what its name tells
|
||||||
type BoolDataType struct{}
|
type BoolDataType struct{}
|
||||||
|
|
||||||
// Kind returns the kind of data
|
// Type returns the type of data
|
||||||
func (BoolDataType) Kind() reflect.Kind {
|
func (BoolDataType) Type() reflect.Type {
|
||||||
return reflect.Bool
|
return reflect.TypeOf(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build returns the validator
|
// Build returns the validator
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
// FloatDataType is what its name tells
|
// FloatDataType is what its name tells
|
||||||
type FloatDataType struct{}
|
type FloatDataType struct{}
|
||||||
|
|
||||||
// Kind returns the kind of data
|
// Type returns the type of data
|
||||||
func (FloatDataType) Kind() reflect.Kind {
|
func (FloatDataType) Type() reflect.Type {
|
||||||
return reflect.Float64
|
return reflect.TypeOf(float64(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build returns the validator
|
// Build returns the validator
|
||||||
|
|
|
@ -11,9 +11,9 @@ import (
|
||||||
// IntDataType is what its name tells
|
// IntDataType is what its name tells
|
||||||
type IntDataType struct{}
|
type IntDataType struct{}
|
||||||
|
|
||||||
// Kind returns the kind of data
|
// Type returns the type of data
|
||||||
func (IntDataType) Kind() reflect.Kind {
|
func (IntDataType) Type() reflect.Type {
|
||||||
return reflect.Int
|
return reflect.TypeOf(int(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build returns the validator
|
// Build returns the validator
|
||||||
|
|
|
@ -14,9 +14,9 @@ var variableLengthRegex = regexp.MustCompile(`^string\((\d+), ?(\d+)\)$`)
|
||||||
// StringDataType is what its name tells
|
// StringDataType is what its name tells
|
||||||
type StringDataType struct{}
|
type StringDataType struct{}
|
||||||
|
|
||||||
// Kind returns the kind of data
|
// Type returns the type of data
|
||||||
func (StringDataType) Kind() reflect.Kind {
|
func (StringDataType) Type() reflect.Type {
|
||||||
return reflect.String
|
return reflect.TypeOf(string(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build returns the validator.
|
// Build returns the validator.
|
||||||
|
|
|
@ -11,9 +11,9 @@ import (
|
||||||
// UintDataType is what its name tells
|
// UintDataType is what its name tells
|
||||||
type UintDataType struct{}
|
type UintDataType struct{}
|
||||||
|
|
||||||
// Kind returns the kind of data
|
// Type returns the type of data
|
||||||
func (UintDataType) Kind() reflect.Kind {
|
func (UintDataType) Type() reflect.Type {
|
||||||
return reflect.Uint
|
return reflect.TypeOf(uint(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build returns the validator
|
// Build returns the validator
|
||||||
|
|
|
@ -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)
|
// 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
|
// to be able to access other datatypes
|
||||||
type T interface {
|
type T interface {
|
||||||
Kind() reflect.Kind
|
Type() reflect.Type
|
||||||
Build(typeDefinition string, registry ...T) Validator
|
Build(typeDefinition string, registry ...T) Validator
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,7 +238,7 @@ func (svc *Service) validateInput(types []datatype.T) error {
|
||||||
param.Validator = dtype.Build(param.Type, types...)
|
param.Validator = dtype.Build(param.Type, types...)
|
||||||
if param.Validator != nil {
|
if param.Validator != nil {
|
||||||
datatypeFound = true
|
datatypeFound = true
|
||||||
param.Kind = dtype.Kind()
|
param.ExtractType = dtype.Type()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,12 @@ type Server struct {
|
||||||
|
|
||||||
// Service represents a service definition (from api.json)
|
// Service represents a service definition (from api.json)
|
||||||
type Service struct {
|
type Service struct {
|
||||||
Method string `json:"method"`
|
Method string `json:"method"`
|
||||||
Pattern string `json:"path"`
|
Pattern string `json:"path"`
|
||||||
Scope [][]string `json:"scope"`
|
Scope [][]string `json:"scope"`
|
||||||
Description string `json:"info"`
|
Description string `json:"info"`
|
||||||
Input map[string]*Parameter `json:"in"`
|
Input map[string]*Parameter `json:"in"`
|
||||||
// Output map[string]*Parameter `json:"out"`
|
Output map[string]interface{} `json:"out"`
|
||||||
|
|
||||||
// references to url parameters
|
// references to url parameters
|
||||||
// format: '/uri/{param}'
|
// format: '/uri/{param}'
|
||||||
|
@ -46,8 +46,8 @@ type Parameter struct {
|
||||||
Description string `json:"info"`
|
Description string `json:"info"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Rename string `json:"name,omitempty"`
|
Rename string `json:"name,omitempty"`
|
||||||
// Kind of data the datatype returns
|
// ExtractType is the type of data the datatype returns
|
||||||
Kind reflect.Kind
|
ExtractType reflect.Type
|
||||||
// Optional is set to true when the type is prefixed with '?'
|
// Optional is set to true when the type is prefixed with '?'
|
||||||
Optional bool
|
Optional bool
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue