Anonymous structs

suggest change

An anonymous struct doesn't have a name:

data := struct {
	Number int
	Text   string
}{
	42,
	"Hello world!",
}

fmt.Printf("data: %+v\n", data)
data: {Number:42 Text:Hello world!}

As a result you can only create values of anonymous struct where point of struct definition.

Anonymous structs are often used in unit tests.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents