Skip to content

Instantly share code, notes, and snippets.

@sanae10001
Created June 8, 2020 05:05
Show Gist options
  • Save sanae10001/e097b8e1afbcddc6ddf4a9c31e91e677 to your computer and use it in GitHub Desktop.
Save sanae10001/e097b8e1afbcddc6ddf4a9c31e91e677 to your computer and use it in GitHub Desktop.
print go struct
func printStruct(i interface{}) {
s := reflect.ValueOf(i).Elem()
typeOfT := s.Type()
for i := 0; i < s.NumField(); i++ {
f := s.Field(i)
fmt.Printf("%d: %s %s = %v\n", i,
typeOfT.Field(i).Name, f.Type(), f.Interface())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment