Revisions
-
drewolson revised this gist
Feb 13, 2013 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,11 +15,11 @@ func (f *Foo) reflect() { val := reflect.ValueOf(f).Elem() for i := 0; i < val.NumField(); i++ { valueField := val.Field(i) typeField := val.Type().Field(i) tag := typeField.Tag fmt.Printf("Field Name: %s,\t Field Value: %v,\t Tag Value: %s\n", typeField.Name, valueField.Interface(), tag.Get("tag_name")) } } -
drewolson revised this gist
Feb 13, 2013 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ package main import ( "fmt" "reflect" ) @@ -26,9 +26,9 @@ func (f *Foo) reflect() { func main() { f := &Foo{ FirstName: "Drew", LastName: "Olson", Age: 30, } f.reflect() } -
drewolson created this gist
Feb 12, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ package main import ( "fmt" "reflect" ) type Foo struct { FirstName string `tag_name:"tag 1"` LastName string `tag_name:"tag 2"` Age int `tag_name:"tag 3"` } func (f *Foo) reflect() { val := reflect.ValueOf(f).Elem() for i := 0; i < val.NumField(); i++ { value_field := val.Field(i) type_field := val.Type().Field(i) tag := type_field.Tag fmt.Printf("Field Name: %s,\t Field Value: %v,\t Tag Value: %s\n", type_field.Name, value_field.Interface(), tag.Get("tag_name")) } } func main() { f := &Foo{ FirstName: "Drew", LastName: "Olson", Age: 30, } f.reflect() }