implement validator interface for config.parameter

This commit is contained in:
Adrien Marquès 2020-03-28 12:28:58 +01:00
parent 54705b7472
commit dac9aa4298
Signed by: xdrm-brackets
GPG Key ID: D75243CA236D825E
1 changed files with 3 additions and 14 deletions

View File

@ -2,8 +2,8 @@ package config
import "git.xdrm.io/go/aicra/datatype" import "git.xdrm.io/go/aicra/datatype"
func (param *Parameter) checkAndFormat() error { // Validate implements the validator interface
func (param *Parameter) Validate(datatypes ...datatype.T) error {
// missing description // missing description
if len(param.Description) < 1 { if len(param.Description) < 1 {
return ErrMissingParamDesc return ErrMissingParamDesc
@ -14,7 +14,7 @@ func (param *Parameter) checkAndFormat() error {
return ErrMissingParamType return ErrMissingParamType
} }
// set optional + type // optional type transform
if param.Type[0] == '?' { if param.Type[0] == '?' {
param.Optional = true param.Optional = true
param.Type = param.Type[1:] param.Type = param.Type[1:]
@ -22,14 +22,3 @@ func (param *Parameter) checkAndFormat() error {
return nil return nil
} }
// assigns the first matching data type from the type definition
func (param *Parameter) assignDataType(types []datatype.T) bool {
for _, dtype := range types {
param.Validator = dtype.Build(param.Type, types...)
if param.Validator != nil {
return true
}
}
return false
}