test dynfunc package; standardize and refactor api #14
|
@ -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")
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue