github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zdi/pre.go (about) 1 package zdi 2 3 import ( 4 "fmt" 5 "reflect" 6 ) 7 8 type PreInvoker interface { 9 Invoke([]interface{}) ([]reflect.Value, error) 10 } 11 12 func IsPreInvoker(handler interface{}) bool { 13 _, ok := handler.(PreInvoker) 14 return ok 15 } 16 17 func (inj *injector) fast(f PreInvoker, t reflect.Type, numIn int) ([]reflect.Value, error) { 18 var in []interface{} 19 if numIn > 0 { 20 in = make([]interface{}, numIn) 21 var argType reflect.Type 22 for i := 0; i < numIn; i++ { 23 argType = t.In(i) 24 val, ok := inj.Get(argType) 25 if !ok { 26 return nil, fmt.Errorf("value not found for type %v", argType) 27 } 28 29 in[i] = val.Interface() 30 } 31 } 32 return f.Invoke(in) 33 }