When trying to add a key to the map which already exists, the new value will override the old value. This is analogous to updating a key in the map. Let’s see…
Tag: golang
Length of string in Go (Golang)
In Golang string is a sequence of bytes. A string literal actually represents a UTF-8 sequence of bytes. In UTF-8, ASCII characters are single-byte corresponding to the first 128 Unicode characters. All other…
Pointer Receiver for a method in Go (Golang)
To better understand pointer receiver we first have to understand the value receiver for a method. Methods on Value Receiver Let’s see an example of a value receiver Output Notice that the…
Method in Go (Golang)
This is the chapter 20 of the golang comprehensive tutorial series. Refer to this link for other chapters of the series – Golang Comprehensive Tutorial Series Next Tutorial – InterfacePrevious Tutorial – Maps Now let’s check…
Method Chaining in Go (Golang)
For method chaining to be possible, the methods in the chain should return the receiver. Returning the receiver for the last method in the chain is optional. Let’s see an example of…
Method on a non-struct type in Go (Golang)
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…
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…