Maps are golang builtin datatype similar to the hash table which maps a key to a value. . Below is the format for a map: Both key_type and value_type can be of…
Category: Tech
Update a key in the map in Go (Golang)
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…
Iterate over a 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…
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…
Declare/Initialize/Create an array or slice in Go (Golang)
Overview Similar to any other programming language, golang also has an array data structure. But in go, arrays behave little differently than other languages and also we have something called slice in…
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….