3 ms·
Reflection, the way Martini used it, was for dependency injection. So in our imaginary Go language, the io.Reader interface could be satisfied by either of two
by nemothekid 9y ago
Reflection, the way Martini used it, was for dependency injection. So in our imaginary Go language, the io.Reader interface could be satisfied by either of two functions:
Read([]byte)
Read(context.Context, []byte)
In a way reflection let you do operator overloading, so in your case you could just call a.Read(p) and others could a.Read(ctx, p). In Martini's case, if you wanted your handler to be cognizant of a cancellable context, you would just add the context parameter.