1
例えば、私がしようとしています何インターフェイス名にメソッド名をリストする方法は?
type FooService interface {
Foo1(x int) int
Foo2(x string) string
}
は、ランタイム・リフレクションを使用してリスト["Foo1", "Foo2"]
を得ています。
例えば、私がしようとしています何インターフェイス名にメソッド名をリストする方法は?
type FooService interface {
Foo1(x int) int
Foo2(x string) string
}
は、ランタイム・リフレクションを使用してリスト["Foo1", "Foo2"]
を得ています。
これを試してみてください:
t := reflect.TypeOf((*FooService)(nil)).Elem()
var s []string
for i := 0; i < t.NumMethod(); i++ {
s = append(s, t.Method(i).Name)
}
インターフェイスタイプのreflect.Typeを取得するには、トリッキーな部分です。説明はHow to get the reflect.Type of an interface?を参照してください。