github.com/wfusion/gofusion@v1.1.14/mq/utils.go (about) 1 package mq 2 3 import ( 4 "reflect" 5 ) 6 7 func wrapParams(fn any) (argType reflect.Type) { 8 typ := reflect.TypeOf(fn) 9 10 inLength := typ.NumIn() 11 if inLength == 1 { 12 return 13 } 14 if inLength >= 2 { 15 return typ.In(1) 16 } 17 18 return 19 } 20 21 func unwrapParams(typ reflect.Type, arg any) (params []any) { 22 if typ == nil { 23 return 24 } 25 26 return []any{arg} 27 } 28 29 func setParams(typ reflect.Type, embed bool, params ...any) (arg any) { 30 if typ == nil { 31 return 32 } 33 34 argValPtr := reflect.New(typ) 35 argVal := argValPtr.Elem() 36 if !embed { 37 if len(params) > 0 { 38 argVal.Set(reflect.ValueOf(params[0])) 39 } 40 return argValPtr.Interface() 41 } 42 43 for i := 0; i < len(params); i++ { 44 ft := argVal.Field(i) 45 ft.Set(reflect.ValueOf(params[i]).Convert(ft.Type())) 46 } 47 return argValPtr.Interface() 48 }