Created
November 1, 2013 04:15
-
-
Save defp/7260883 to your computer and use it in GitHub Desktop.
reflect.go
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 Post struct { | |
| Id int `field:"id"` | |
| Title string `field:"title"` | |
| Content string `field:"content"` | |
| } | |
| func main() { | |
| var post Post | |
| post.Id = 1 | |
| post.Title = "hello" | |
| post.Content = "helloworld" | |
| t := reflect.TypeOf(post) | |
| for i := 0; i < t.NumField(); i++ { | |
| tag := t.Field(i).Tag | |
| fmt.Println(tag.Get("field")) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment