Skip to content

Instantly share code, notes, and snippets.

@buksy
Forked from drewolson/reflection.go
Last active August 29, 2015 14:15

Revisions

  1. @drewolson drewolson revised this gist Feb 13, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions reflection.go
    Original 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++ {
    value_field := val.Field(i)
    type_field := val.Type().Field(i)
    tag := type_field.Tag
    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", type_field.Name, value_field.Interface(), tag.Get("tag_name"))
    fmt.Printf("Field Name: %s,\t Field Value: %v,\t Tag Value: %s\n", typeField.Name, valueField.Interface(), tag.Get("tag_name"))
    }
    }

  2. @drewolson drewolson revised this gist Feb 13, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions reflection.go
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    package main

    import (
    "fmt"
    "fmt"
    "reflect"
    )

    @@ -26,9 +26,9 @@ func (f *Foo) reflect() {
    func main() {
    f := &Foo{
    FirstName: "Drew",
    LastName: "Olson",
    Age: 30,
    LastName: "Olson",
    Age: 30,
    }

    f.reflect()
    }
    }
  3. @drewolson drewolson created this gist Feb 12, 2013.
    34 changes: 34 additions & 0 deletions reflection.go
    Original 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()
    }