For example,
type FooService interface {
Foo1(x int) int
Foo2(x string) string
}
What I am attempting to do is getting list ["Foo1", "Foo2"]
using runtime reflection.
Try this:
t := reflect.TypeOf((*FooService)(nil)).Elem()
var s []string
for i := 0; i < t.NumMethod(); i++ {
s = append(s, t.Method(i).Name)
}
playground example
Getting the reflect.Type for the interface type is the tricky part. See How to get the reflect.Type of an interface? for an explanation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With