Add dynamic handler management #13
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue