@@ -188,16 +188,14 @@ func (def *ArgsDef) StringArgsFunc(commandFunc interface{}, resultsHandlers []Re
188
188
return nil , err
189
189
}
190
190
191
- return func (ctx context.Context , callerArgs ... string ) error {
191
+ f := func (ctx context.Context , callerArgs ... string ) error {
192
192
argVals , err := def .argValsFromStringArgs (callerArgs )
193
193
if err != nil {
194
194
return err
195
195
}
196
- if dispatcher .firstArgIsContext {
197
- argVals = append ([]reflect.Value {reflect .ValueOf (ctx )}, argVals ... )
198
- }
199
- return dispatcher .callWithResultsHandlers (argVals , resultsHandlers )
200
- }, nil
196
+ return dispatcher .callWithResultsHandlers (ctx , argVals , resultsHandlers )
197
+ }
198
+ return f , nil
201
199
}
202
200
203
201
func (def * ArgsDef ) StringMapArgsFunc (commandFunc interface {}, resultsHandlers []ResultsHandler ) (StringMapArgsFunc , error ) {
@@ -206,16 +204,14 @@ func (def *ArgsDef) StringMapArgsFunc(commandFunc interface{}, resultsHandlers [
206
204
return nil , err
207
205
}
208
206
209
- return func (ctx context.Context , callerArgs map [string ]string ) (err error ) {
207
+ f := func (ctx context.Context , callerArgs map [string ]string ) (err error ) {
210
208
argVals , err := def .argValsFromStringMapArgs (callerArgs )
211
209
if err != nil {
212
210
return err
213
211
}
214
- if dispatcher .firstArgIsContext {
215
- argVals = append ([]reflect.Value {reflect .ValueOf (ctx )}, argVals ... )
216
- }
217
- return dispatcher .callWithResultsHandlers (argVals , resultsHandlers )
218
- }, nil
212
+ return dispatcher .callWithResultsHandlers (ctx , argVals , resultsHandlers )
213
+ }
214
+ return f , nil
219
215
}
220
216
221
217
func (def * ArgsDef ) MapArgsFunc (commandFunc interface {}, resultsHandlers []ResultsHandler ) (MapArgsFunc , error ) {
@@ -224,16 +220,14 @@ func (def *ArgsDef) MapArgsFunc(commandFunc interface{}, resultsHandlers []Resul
224
220
return nil , err
225
221
}
226
222
227
- return func (ctx context.Context , callerArgs map [string ]interface {}) (err error ) {
223
+ f := func (ctx context.Context , callerArgs map [string ]interface {}) (err error ) {
228
224
argVals , err := def .argValsFromMapArgs (callerArgs )
229
225
if err != nil {
230
226
return err
231
227
}
232
- if dispatcher .firstArgIsContext {
233
- argVals = append ([]reflect.Value {reflect .ValueOf (ctx )}, argVals ... )
234
- }
235
- return dispatcher .callWithResultsHandlers (argVals , resultsHandlers )
236
- }, nil
228
+ return dispatcher .callWithResultsHandlers (ctx , argVals , resultsHandlers )
229
+ }
230
+ return f , nil
237
231
}
238
232
239
233
func (def * ArgsDef ) JSONArgsFunc (commandFunc interface {}, resultsHandlers []ResultsHandler ) (JSONArgsFunc , error ) {
@@ -242,16 +236,14 @@ func (def *ArgsDef) JSONArgsFunc(commandFunc interface{}, resultsHandlers []Resu
242
236
return nil , err
243
237
}
244
238
245
- return func (ctx context.Context , callerArgs []byte ) (err error ) {
239
+ f := func (ctx context.Context , callerArgs []byte ) (err error ) {
246
240
argVals , err := def .argValsFromJSON (callerArgs )
247
241
if err != nil {
248
242
return err
249
243
}
250
- if dispatcher .firstArgIsContext {
251
- argVals = append ([]reflect.Value {reflect .ValueOf (ctx )}, argVals ... )
252
- }
253
- return dispatcher .callWithResultsHandlers (argVals , resultsHandlers )
254
- }, nil
244
+ return dispatcher .callWithResultsHandlers (ctx , argVals , resultsHandlers )
245
+ }
246
+ return f , nil
255
247
}
256
248
257
249
func (def * ArgsDef ) StringArgsResultValuesFunc (commandFunc interface {}) (StringArgsResultValuesFunc , error ) {
@@ -260,16 +252,14 @@ func (def *ArgsDef) StringArgsResultValuesFunc(commandFunc interface{}) (StringA
260
252
return nil , err
261
253
}
262
254
263
- return func (ctx context.Context , args []string ) ([]reflect.Value , error ) {
255
+ f := func (ctx context.Context , args []string ) ([]reflect.Value , error ) {
264
256
argVals , err := def .argValsFromStringArgs (args )
265
257
if err != nil {
266
258
return nil , err
267
259
}
268
- if dispatcher .firstArgIsContext {
269
- argVals = append ([]reflect.Value {reflect .ValueOf (ctx )}, argVals ... )
270
- }
271
- return dispatcher .callAndReturnResults (argVals )
272
- }, nil
260
+ return dispatcher .callAndReturnResults (ctx , argVals )
261
+ }
262
+ return f , nil
273
263
}
274
264
275
265
func (def * ArgsDef ) StringMapArgsResultValuesFunc (commandFunc interface {}) (StringMapArgsResultValuesFunc , error ) {
@@ -278,16 +268,14 @@ func (def *ArgsDef) StringMapArgsResultValuesFunc(commandFunc interface{}) (Stri
278
268
return nil , err
279
269
}
280
270
281
- return func (ctx context.Context , args map [string ]string ) ([]reflect.Value , error ) {
271
+ f := func (ctx context.Context , args map [string ]string ) ([]reflect.Value , error ) {
282
272
argVals , err := def .argValsFromStringMapArgs (args )
283
273
if err != nil {
284
274
return nil , err
285
275
}
286
- if dispatcher .firstArgIsContext {
287
- argVals = append ([]reflect.Value {reflect .ValueOf (ctx )}, argVals ... )
288
- }
289
- return dispatcher .callAndReturnResults (argVals )
290
- }, nil
276
+ return dispatcher .callAndReturnResults (ctx , argVals )
277
+ }
278
+ return f , nil
291
279
}
292
280
293
281
func (def * ArgsDef ) MapArgsResultValuesFunc (commandFunc interface {}) (MapArgsResultValuesFunc , error ) {
@@ -296,16 +284,14 @@ func (def *ArgsDef) MapArgsResultValuesFunc(commandFunc interface{}) (MapArgsRes
296
284
return nil , err
297
285
}
298
286
299
- return func (ctx context.Context , args map [string ]interface {}) ([]reflect.Value , error ) {
287
+ f := func (ctx context.Context , args map [string ]interface {}) ([]reflect.Value , error ) {
300
288
argVals , err := def .argValsFromMapArgs (args )
301
289
if err != nil {
302
290
return nil , err
303
291
}
304
- if dispatcher .firstArgIsContext {
305
- argVals = append ([]reflect.Value {reflect .ValueOf (ctx )}, argVals ... )
306
- }
307
- return dispatcher .callAndReturnResults (argVals )
308
- }, nil
292
+ return dispatcher .callAndReturnResults (ctx , argVals )
293
+ }
294
+ return f , nil
309
295
}
310
296
311
297
func (def * ArgsDef ) JSONArgsResultValuesFunc (commandFunc interface {}) (JSONArgsResultValuesFunc , error ) {
@@ -314,14 +300,12 @@ func (def *ArgsDef) JSONArgsResultValuesFunc(commandFunc interface{}) (JSONArgsR
314
300
return nil , err
315
301
}
316
302
317
- return func (ctx context.Context , argsJSON []byte ) ([]reflect.Value , error ) {
303
+ f := func (ctx context.Context , argsJSON []byte ) ([]reflect.Value , error ) {
318
304
argVals , err := def .argValsFromJSON (argsJSON )
319
305
if err != nil {
320
306
return nil , err
321
307
}
322
- if dispatcher .firstArgIsContext {
323
- argVals = append ([]reflect.Value {reflect .ValueOf (ctx )}, argVals ... )
324
- }
325
- return dispatcher .callAndReturnResults (argVals )
326
- }, nil
308
+ return dispatcher .callAndReturnResults (ctx , argVals )
309
+ }
310
+ return f , nil
327
311
}
0 commit comments