File tree 2 files changed +12
-16
lines changed
2 files changed +12
-16
lines changed Original file line number Diff line number Diff line change @@ -186,24 +186,19 @@ type paramTypesOpt struct{}
186
186
// Action for paramTypesOpt override the other param types mapping/config.
187
187
// The val must be string(e.g. "int, object"), and will then assign to the target.(dubboTarget).Types
188
188
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 , "," )
194
189
dubboTarget , ok := target .(* dubboTarget )
195
190
if ! ok {
196
191
return errors .New ("Target is not dubboTarget in target parameter" )
197
192
}
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
+ }
205
201
}
206
- types [i ] = trimType
207
202
}
208
203
dubboTarget .Types = types
209
204
return nil
Original file line number Diff line number Diff line change @@ -84,14 +84,15 @@ func TestParamTypesOptAction(t *testing.T) {
84
84
assert .Equal (t , "string" , target .Types [1 ])
85
85
86
86
err = opt .Action (target , "object,whatsoever" )
87
- assert .EqualError (t , err , "Types invalid whatsoever" )
87
+ assert .Nil (t , err )
88
88
89
89
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 " )
91
91
err = opt .Action (target , "object," )
92
92
assert .Nil (t , err )
93
93
assert .Equal (t , "object" , target .Types [0 ])
94
- err = opt .Action (target , "object" )
94
+
95
+ err = opt .Action (target , "object " )
95
96
assert .Nil (t , err )
96
97
assert .Equal (t , "object" , target .Types [0 ])
97
98
}
You can’t perform that action at this time.
0 commit comments