Skip to content

Instantly share code, notes, and snippets.

@hiyosi
Last active August 29, 2015 14:08
Show Gist options
  • Save hiyosi/2f0d5d0a7ca7f060dc64 to your computer and use it in GitHub Desktop.
Save hiyosi/2f0d5d0a7ca7f060dc64 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"reflect"
)
type Meta struct {
Name string `json:"name" ham:"true" spam:"false"`
Version string `json:"version" ham:"false" spam:"true"`
}
func main() {
result := &Meta{
Name : "eggs",
Version : "1",
}
rt, rv:= reflect.TypeOf(*result), reflect.ValueOf(*result)
for i :=0; i < rt.NumField(); i++ {
field := rt.Field(i)
ham := field.Tag.Get("ham")
spam := field.Tag.Get("spam")
json := field.Tag.Get("json")
fmt.Printf("[Tag] json:%s, ham:%s, spam:%s\n", json, ham, spam)
fmt.Printf("[Value] %s\n\n", rv.Field(i).Interface())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment