This is an automated email from the ASF dual-hosted git repository. baerwang pushed a commit to branch 1.0.0 in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu.git
The following commit(s) were added to refs/heads/1.0.0 by this push: new 8654c60d remove unused types JTypeMapper check & support default types. (#597) 8654c60d is described below commit 8654c60d960f6df9044f3a72788ba4327be2e18f Author: Mark4z <36187602+mar...@users.noreply.github.com> AuthorDate: Sun Dec 3 03:45:21 2023 +0800 remove unused types JTypeMapper check & support default types. (#597) --- pixiu/pkg/client/dubbo/option.go | 21 ++++++++------------- pixiu/pkg/client/dubbo/option_test.go | 7 ++++--- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/pixiu/pkg/client/dubbo/option.go b/pixiu/pkg/client/dubbo/option.go index 41980f73..1d1aae2e 100644 --- a/pixiu/pkg/client/dubbo/option.go +++ b/pixiu/pkg/client/dubbo/option.go @@ -186,24 +186,19 @@ type paramTypesOpt struct{} // Action for paramTypesOpt override the other param types mapping/config. // The val must be string(e.g. "int, object"), and will then assign to the target.(dubboTarget).Types func (opt *paramTypesOpt) Action(target, val interface{}) error { - v, ok := val.(string) - if !ok { - return errors.New("The val type must be string") - } - types := strings.Split(v, ",") dubboTarget, ok := target.(*dubboTarget) if !ok { return errors.New("Target is not dubboTarget in target parameter") } - for i := range types { - trimType := strings.TrimSpace(types[i]) - if len(trimType) == 0 { - continue - } - if _, ok = constant.JTypeMapper[trimType]; !ok { - return errors.Errorf("Types invalid %s", trimType) + // empty types for func like func() + types := make([]string, 0) + if v, ok := val.(string); ok { + if len(v) > 0 { + types = strings.Split(v, ",") + for i := range types { + types[i] = strings.TrimSpace(types[i]) + } } - types[i] = trimType } dubboTarget.Types = types return nil diff --git a/pixiu/pkg/client/dubbo/option_test.go b/pixiu/pkg/client/dubbo/option_test.go index e8762e59..179ef1b5 100644 --- a/pixiu/pkg/client/dubbo/option_test.go +++ b/pixiu/pkg/client/dubbo/option_test.go @@ -84,14 +84,15 @@ func TestParamTypesOptAction(t *testing.T) { assert.Equal(t, "string", target.Types[1]) err = opt.Action(target, "object,whatsoever") - assert.EqualError(t, err, "Types invalid whatsoever") + assert.Nil(t, err) err = opt.Action("target", []string{}) - assert.EqualError(t, err, "The val type must be string") + assert.EqualError(t, err, "Target is not dubboTarget in target parameter") err = opt.Action(target, "object,") assert.Nil(t, err) assert.Equal(t, "object", target.Types[0]) - err = opt.Action(target, "object") + + err = opt.Action(target, "object ") assert.Nil(t, err) assert.Equal(t, "object", target.Types[0]) }