test dynfunc package; standardize and refactor api #14

Merged
xdrm-brackets merged 19 commits from test/dynamic into 0.3.0 2020-04-04 10:09:20 +00:00
2 changed files with 19 additions and 1 deletions
Showing only changes of commit 66985dfbd0 - Show all commits

View File

@ -29,6 +29,9 @@ const ErrMissingRequestArgument = cerr("handler first argument must be of type a
// ErrMissingParamArgument - missing parameters argument for handler // ErrMissingParamArgument - missing parameters argument for handler
const ErrMissingParamArgument = cerr("handler second argument must be a struct") 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 // ErrMissingParamOutput - missing output argument for handler
const ErrMissingParamOutput = cerr("handler first output must be a *struct") const ErrMissingParamOutput = cerr("handler first output must be a *struct")

View File

@ -3,6 +3,7 @@ package dynamic
import ( import (
"fmt" "fmt"
"reflect" "reflect"
"strings"
"git.xdrm.io/go/aicra/api" "git.xdrm.io/go/aicra/api"
"git.xdrm.io/go/aicra/internal/config" "git.xdrm.io/go/aicra/internal/config"
@ -50,8 +51,15 @@ func (s spec) checkInput(fnv reflect.Value) error {
return ErrMissingParamArgument return ErrMissingParamArgument
} }
// check for invlaid param // check for invalid param
for name, ptype := range s.Input { 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) field, exists := structArg.FieldByName(name)
if !exists { if !exists {
return fmt.Errorf("%s: %w", name, ErrMissingParamFromConfig) return fmt.Errorf("%s: %w", name, ErrMissingParamFromConfig)
@ -100,6 +108,13 @@ func (s spec) checkOutput(fnv reflect.Value) error {
// fail on invalid output // fail on invalid output
for name, ptype := range s.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) field, exists := structOutput.FieldByName(name)
if !exists { if !exists {
return fmt.Errorf("%s: %w", name, ErrMissingOutputFromConfig) return fmt.Errorf("%s: %w", name, ErrMissingOutputFromConfig)