to make you to fall in love with Golang 」 1 / 11 Structs Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
that contains a collection of named fields. is a schema containing the blueprint of the data that the structure will hold 2 / 11 Structs Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
of a struct is a struct with all fields set to their own zero values. Try It! 「Trying to make you to fall in love with Golang」 - Structs 3 / 11 Structs Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
pass the field values in the same order in which they are declared in the struct you can’t initialize only a subset of fields with this syntax Try It! 「Trying to make you to fall in love with Golang」 - Structs 4 / 11 Structs Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
case the order of fields is irrelevant if you want, with this syntax, you can initialize even a subset of fields only Try It! 「Trying to make you to fall in love with Golang」 - Structs 5 / 11 Structs Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
struct using the dot ( . ) operator. Try It! 「Trying to make you to fall in love with Golang」 - Structs 6 / 11 Structs Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
data type. great for unmarshalling JSON data in HTTP handlers If a struct is only meant to be used once, then it makes sense to declare it as anonymous. Try It! 「Trying to make you to fall in love with Golang」 - Structs 7 / 11 Structs Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
without declaring any field names. by default the name of an anonymous field is the name of its type we are allowed to mix anonymous fields with named fields Try It! 「Trying to make you to fall in love with Golang」 - Structs 8 / 11 Structs Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
another struct. you can access (or update) fields of a nested struct using the ( . ) dot notation as usual Try It! 「Trying to make you to fall in love with Golang」 - Structs 9 / 11 Structs Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
on parent struct - that's what is called field promotion. the anonymous field Location has been promoted to parent struct User we can access this field as if it were defined on the User struct Try It! 10 / 11 Structs Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
(@night) {twitter.com, github.com, linkedin.com} / lucasepe 「Trying to make you to fall in love with Golang」 - Structs 11 / 11 Structs Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/