To print structs we use the fmt package i.e fmt.Printf(ā%vā, structName). This will print the struct in the format of a map. To print the struct in a more readable format we use the %#v format specifier. This will print the struct in the format of a struct.
Output:
we can also convert the struct to JSON and then print the elements of the struct
Output:
How to print a nested struct in Go
To print a nested struct we use the %#v format specifier. This will print the struct in the format of a struct.
Output:
How to print a struct with a slice in Go
To print a struct with a slice we use the %#v format specifier. This will print the struct in the format of a struct.
Output:
Subscribe to my newsletter
Get the latest posts delivered right to your inbox.