Bind binds a type to another. Useful when binding implementation to interfaces. The arguments should be a ptr to the binding types, rather than the types themselves. For example: Bind(new(MyConcreteStruct), new(MyAbstractInterface))
(from interface{}, to interface{})
| 62 | // the types themselves. For example: |
| 63 | // Bind(new(MyConcreteStruct), new(MyAbstractInterface)) |
| 64 | func Bind(from interface{}, to interface{}) interface{} { |
| 65 | fromTypes := []reflect.Type{reflect.TypeOf(from).Elem()} |
| 66 | toTypes := []reflect.Type{reflect.TypeOf(to).Elem()} |
| 67 | fnType := reflect.FuncOf(fromTypes, toTypes, false /* variadic */) |
| 68 | fn := reflect.MakeFunc(fnType, func(args []reflect.Value) []reflect.Value { |
| 69 | return args |
| 70 | }) |
| 71 | return fn.Interface() |
| 72 | } |
no outgoing calls