Avatar ·

How to output a struct to the console in Go: a complete breakdown of methods

Hello everyone! I just started learning Go and encountered this problem: I have a struct describing, for example, a user: ```go type User struct { Name string Age int Email string } ``` I create an instance of this struct: ```go user := User{Name: "Ivan", Age: 30, Email: "ivan@example.com"} ``` And I try to output it to the console using `fmt.Println(user)` or `fmt.Printf("%v", user)`. As a result, I see something like `{Ivan 30 ivan@example.com}` — which is, of course, better than nothing, but not very readable. Especially if there are many fields or the struct is nested. What I want: 1. To see the field names (Name, Age, Email) in the output. 2. For the struct to be displayed in a readable format, possibly with indentation. 3. For this to work for any struct, not just mine.