Created
June 8, 2020 05:05
-
-
Save sanae10001/e097b8e1afbcddc6ddf4a9c31e91e677 to your computer and use it in GitHub Desktop.
print go struct
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 characters
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