delegate from internal.service to parameter.Validate()

This commit is contained in:
Adrien Marquès 2020-03-29 14:12:47 +02:00
parent 76cc2f5279
commit b15bb578ce
Signed by: xdrm-brackets
GPG Key ID: D75243CA236D825E
2 changed files with 16 additions and 16 deletions

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 {