One minute
Anonymous structs in Go
In this article we will see how anonymous structs works in golang. Generally in go, structs are declared as
and later a new variable is created of the above struct type like below
but instead of this you can also use anonymous structs, which is a subtle feature of go lang. It makes it easier for you to avoide creating extra struct types.
You can create anonymous structs in go like this
Such implementation of anonymous structs are seen commonly while creating unit tests in go.
Here is a full program with its output
Output:
Read other posts