Skip to content

Instantly share code, notes, and snippets.

@jeanbza
Created June 9, 2014 02:26
Show Gist options
  • Save jeanbza/37ef96e1b4ba707b87ec to your computer and use it in GitHub Desktop.
Save jeanbza/37ef96e1b4ba707b87ec to your computer and use it in GitHub Desktop.
Printing the functions of a Go struct
package main
import (
"fmt"
"reflect"
)
type A struct {
}
func (a *A) Hello() {
fmt.Println("Hello")
}
func (a *A) World() {
fmt.Println("World!")
}
func main() {
// Print the two functions of A
fooType := reflect.TypeOf(&A{})
for i := 0; i < fooType.NumMethod(); i++ {
method := fooType.Method(i)
fmt.Println(method.Name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment