Methods can also be defined on a non-struct custom type. Non-struct custom types can be created through type definition. Below is the format for creating a new custom type For example we…
Tag: go
Struct Field Meta or Tags in Go (Golang)
A struct in go also allows adding metadata to its fields. These meta fields can be used to encode decode into different forms, doing some forms of validations on struct fields, etc….
Accessing and Setting Struct Fields in Go (Golang)
Overview GO struct is named collection of data fields which can be of different types. Struct acts as a container that has different heterogeneous data types which together represents an entity. For…
Nested Struct in Go (Golang)
A struct can have an another struct nested in it. Let’s see an example of a nested struct. In below employee struct has address struct nested it in. Output Notice how nested…
Anonymous Fields in a Struct in Go (Golang)
A struct can have anonymous fields as well, meaning a field having no name. The type will become the field name. In below example, string will be the field name as well The…
Declare or create/initialize struct variable in Go (Golang
Overview GO struct is named collection of data fields which can be of different types. Struct acts as a container that has different heterogeneous data types which together represents an entity. For…
Struct in Go (Golang)
This is the chapter 16 of the golang comprehensive tutorial series. Refer to this link for other chapters of the series – Golang Comprehensive Tutorial Series Next Tutorial – ArrayPrevious Tutorial – Pointer Now let’s check…
Check if two structs are equal or struct equality in Go (Golang)
The first thing to know before considering struct equality is weather if all struct fields types are comparable or not Some of the comparable types as defined by go specification are boolean…
Exported and UnExported fields of a struct in Go (Golang)
Go doesn’t have any public, private or protected keyword. The only mechanism to control the visibility outside the package is using the capitalized and non-capitalized formats Capitalized Identifiers are exported. The capital letter…
Pretty print struct variables in Go (Golang)
Note: If you are interested in learning Golang, then for that we have a golang comprehensive tutorial series. Do check it out – Golang Comprehensive Tutorial Series. Now let’s see the current tutorial….