From b15bb578cefb9482eb6c6006e50f52640bbfb5ed Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 29 Mar 2020 14:12:47 +0200 Subject: [PATCH] delegate from internal.service to parameter.Validate() --- internal/config/parameter.go | 14 ++++++++++++++ internal/config/service.go | 18 ++---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/config/parameter.go b/internal/config/parameter.go index 4037ee6..757a09e 100644 --- a/internal/config/parameter.go +++ b/internal/config/parameter.go @@ -20,5 +20,19 @@ func (param *Parameter) Validate(datatypes ...datatype.T) error { 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 } diff --git a/internal/config/service.go b/internal/config/service.go index 7c20724..224de81 100644 --- a/internal/config/service.go +++ b/internal/config/service.go @@ -222,7 +222,7 @@ func (svc *Service) validateInput(types []datatype.T) error { param.Rename = paramName } - err := param.Validate() + err := param.Validate(types...) if err != nil { 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) } - // assign the datatype - 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 + // fail on name/rename conflict for paramName2, param2 := range svc.Input { // ignore self if paramName == paramName2 {