From dac9aa4298330f431672236d11be378749796245 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 28 Mar 2020 12:28:58 +0100 Subject: [PATCH] implement validator interface for config.parameter --- internal/config/parameter.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/internal/config/parameter.go b/internal/config/parameter.go index 9dc43fa..4037ee6 100644 --- a/internal/config/parameter.go +++ b/internal/config/parameter.go @@ -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 -}