Skip to content

Commit

Permalink
remove unused types JTypeMapper check & support default types. (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark4z authored Dec 2, 2023
1 parent 55bb412 commit 8654c60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
21 changes: 8 additions & 13 deletions pixiu/pkg/client/dubbo/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions pixiu/pkg/client/dubbo/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}

0 comments on commit 8654c60

Please sign in to comment.