Created
December 20, 2018 13:27
-
-
Save dkarbayev/8429cf26c804baa0119bf66af6b41485 to your computer and use it in GitHub Desktop.
This file contains 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 MyType struct { | |
Name string | |
Age int | |
Height float32 | |
Alive bool | |
} | |
func main() { | |
x := MyType{ | |
"Dan", | |
29, | |
177.5, | |
true, | |
} | |
t := reflect.TypeOf(x) | |
v := reflect.ValueOf(x) | |
for i := 0; i < t.NumField(); i++ { | |
n := t.Field(i).Name | |
fmt.Println(n, "=", v.FieldByName(n).Interface()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment