Created
June 9, 2014 02:26
-
-
Save jeanbza/37ef96e1b4ba707b87ec to your computer and use it in GitHub Desktop.
Printing the functions of a Go struct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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