Created
November 9, 2012 21:03
-
-
Save aaronlifton3/4048220 to your computer and use it in GitHub Desktop.
Golang instrospection
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
| func getFields() { | |
| t := reflect.TypeOf(model.Post{}) | |
| fmt.Printf("%v\n", t.Name()) | |
| for i := 0; i < t.NumField(); i++ { | |
| field := t.Field(i) | |
| fmt.Printf("%v\n", field.Name) | |
| } | |
| } | |
| func getInterfaces(file *ast.File) *ast.Field { | |
| for _, d := range file.Decls { | |
| if d, ok := d.(*ast.GenDecl); ok && d.Tok == token.TYPE { | |
| for _, s := range d.Specs { | |
| s, _ := s.(*ast.TypeSpec) | |
| println(s.Name.String()) | |
| } | |
| } | |
| } | |
| return nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment