diff --git a/dynamic/errors.go b/dynamic/errors.go index e3d7546..891f254 100644 --- a/dynamic/errors.go +++ b/dynamic/errors.go @@ -29,6 +29,9 @@ const ErrMissingRequestArgument = cerr("handler first argument must be of type a // ErrMissingParamArgument - missing parameters argument for handler const ErrMissingParamArgument = cerr("handler second argument must be a struct") +// ErrUnexportedParamName - argument is unexported in struct +const ErrUnexportedName = cerr("unexported name") + // ErrMissingParamOutput - missing output argument for handler const ErrMissingParamOutput = cerr("handler first output must be a *struct") diff --git a/dynamic/spec.go b/dynamic/spec.go index 354df52..83c6dd0 100644 --- a/dynamic/spec.go +++ b/dynamic/spec.go @@ -3,6 +3,7 @@ package dynamic import ( "fmt" "reflect" + "strings" "git.xdrm.io/go/aicra/api" "git.xdrm.io/go/aicra/internal/config" @@ -50,8 +51,15 @@ func (s spec) checkInput(fnv reflect.Value) error { return ErrMissingParamArgument } - // check for invlaid param + // check for invalid param for name, ptype := range s.Input { + if len(name) < 1 { + continue + } + if name[0] == strings.ToLower(name)[0] { + return fmt.Errorf("%s: %w", name, ErrUnexportedName) + } + field, exists := structArg.FieldByName(name) if !exists { return fmt.Errorf("%s: %w", name, ErrMissingParamFromConfig) @@ -100,6 +108,13 @@ func (s spec) checkOutput(fnv reflect.Value) error { // fail on invalid output for name, ptype := range s.Output { + if len(name) < 1 { + continue + } + if name[0] == strings.ToLower(name)[0] { + return fmt.Errorf("%s: %w", name, ErrUnexportedName) + } + field, exists := structOutput.FieldByName(name) if !exists { return fmt.Errorf("%s: %w", name, ErrMissingOutputFromConfig)