Add dynamic handler management #13

Merged
xdrm-brackets merged 12 commits from feature/dynamic-handler-signature into 0.3.0 2020-03-29 15:10:06 +00:00
2 changed files with 16 additions and 16 deletions
Showing only changes of commit b15bb578ce - Show all commits

View File

@ -20,5 +20,19 @@ func (param *Parameter) Validate(datatypes ...datatype.T) error {
param.Type = param.Type[1:] param.Type = param.Type[1:]
} }
// assign the datatype
datatypeFound := false
for _, dtype := range datatypes {
param.Validator = dtype.Build(param.Type, datatypes...)
if param.Validator != nil {
datatypeFound = true
param.ExtractType = dtype.Type()
break
}
}
if !datatypeFound {
return ErrUnknownDataType
}
return nil return nil
} }

View File

@ -222,7 +222,7 @@ func (svc *Service) validateInput(types []datatype.T) error {
param.Rename = paramName param.Rename = paramName
} }
err := param.Validate() err := param.Validate(types...)
if err != nil { if err != nil {
return fmt.Errorf("%s: %w", paramName, err) return fmt.Errorf("%s: %w", paramName, err)
} }
@ -232,21 +232,7 @@ func (svc *Service) validateInput(types []datatype.T) error {
return fmt.Errorf("%s: %w", paramName, ErrIllegalOptionalURIParam) return fmt.Errorf("%s: %w", paramName, ErrIllegalOptionalURIParam)
} }
// assign the datatype // fail on name/rename conflict
datatypeFound := false
for _, dtype := range types {
param.Validator = dtype.Build(param.Type, types...)
if param.Validator != nil {
datatypeFound = true
param.ExtractType = dtype.Type()
break
}
}
if !datatypeFound {
return fmt.Errorf("%s: %w", paramName, ErrUnknownDataType)
}
// check for name/rename conflict
for paramName2, param2 := range svc.Input { for paramName2, param2 := range svc.Input {
// ignore self // ignore self
if paramName == paramName2 { if paramName == paramName2 {