Skip to content

Instantly share code, notes, and snippets.

@automaticalldramatic
Last active August 21, 2019 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save automaticalldramatic/9f256b8c5222a5cdfae15cd17aa58294 to your computer and use it in GitHub Desktop.
Save automaticalldramatic/9f256b8c5222a5cdfae15cd17aa58294 to your computer and use it in GitHub Desktop.
List out all the values in a struct
// testing output
reflectedStruct := reflect.ValueOf(event)
// in case you want to list all values stored at the location of this pointer to a struct
if reflectedStruct.Kind() == reflect.Ptr {
reflectedStruct = reflectedStruct.Elem()
}
structType := reflectedStruct.Type()
values := make(map[string]interface{}, reflectedStruct.NumField())
for i := 0; i < reflectedStruct.NumField(); i++ {
values[structType.Field(i).Name] = reflectedStruct.Field(i).Interface()
log.Printf("%s: %v", structType.Field(i).Name, reflectedStruct.Field(i).Interface())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment