Skip to content

Commit 8654c60

Browse files
authored
remove unused types JTypeMapper check & support default types. (#597)
1 parent 55bb412 commit 8654c60

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

pixiu/pkg/client/dubbo/option.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -186,24 +186,19 @@ type paramTypesOpt struct{}
186186
// Action for paramTypesOpt override the other param types mapping/config.
187187
// The val must be string(e.g. "int, object"), and will then assign to the target.(dubboTarget).Types
188188
func (opt *paramTypesOpt) Action(target, val interface{}) error {
189-
v, ok := val.(string)
190-
if !ok {
191-
return errors.New("The val type must be string")
192-
}
193-
types := strings.Split(v, ",")
194189
dubboTarget, ok := target.(*dubboTarget)
195190
if !ok {
196191
return errors.New("Target is not dubboTarget in target parameter")
197192
}
198-
for i := range types {
199-
trimType := strings.TrimSpace(types[i])
200-
if len(trimType) == 0 {
201-
continue
202-
}
203-
if _, ok = constant.JTypeMapper[trimType]; !ok {
204-
return errors.Errorf("Types invalid %s", trimType)
193+
// empty types for func like func()
194+
types := make([]string, 0)
195+
if v, ok := val.(string); ok {
196+
if len(v) > 0 {
197+
types = strings.Split(v, ",")
198+
for i := range types {
199+
types[i] = strings.TrimSpace(types[i])
200+
}
205201
}
206-
types[i] = trimType
207202
}
208203
dubboTarget.Types = types
209204
return nil

pixiu/pkg/client/dubbo/option_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ func TestParamTypesOptAction(t *testing.T) {
8484
assert.Equal(t, "string", target.Types[1])
8585

8686
err = opt.Action(target, "object,whatsoever")
87-
assert.EqualError(t, err, "Types invalid whatsoever")
87+
assert.Nil(t, err)
8888

8989
err = opt.Action("target", []string{})
90-
assert.EqualError(t, err, "The val type must be string")
90+
assert.EqualError(t, err, "Target is not dubboTarget in target parameter")
9191
err = opt.Action(target, "object,")
9292
assert.Nil(t, err)
9393
assert.Equal(t, "object", target.Types[0])
94-
err = opt.Action(target, "object")
94+
95+
err = opt.Action(target, "object ")
9596
assert.Nil(t, err)
9697
assert.Equal(t, "object", target.Types[0])
9798
}

0 commit comments

Comments
 (0)