Add validator interface to unify and for readability #11

Merged
xdrm-brackets merged 6 commits from refactor/config-validator into 0.3.0 2020-03-28 11:33:35 +00:00
1 changed files with 3 additions and 14 deletions
Showing only changes of commit dac9aa4298 - Show all commits

View File

@ -2,8 +2,8 @@ package config
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
if len(param.Description) < 1 {
return ErrMissingParamDesc
@ -14,7 +14,7 @@ func (param *Parameter) checkAndFormat() error {
return ErrMissingParamType
}
// set optional + type
// optional type transform
if param.Type[0] == '?' {
param.Optional = true
param.Type = param.Type[1:]
@ -22,14 +22,3 @@ func (param *Parameter) checkAndFormat() error {
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
}