Golang Receiver Function

In Go, a receiver function, often called a method, is a function that has a “special receiver argument that associates the function with a specific type”. This allows you to invoke the function using the dot (.) notation on a value of that type. Receiver functions are similar to the concept of methods in object-oriented … Read more

Golang For Loop: How to Iterate Variables in Go

Golang doesn’t have a while, or do-while loops, which are present in other languages like C. But Golang has for loop. Now let’s go back to the history of iteration. Survey of Definite Iteration in Programming Definite iteration loops are usually referred to as for loops because they are the keyword used to propose them in nearly … Read more

Golang Interface: The Complete Guide

If you are new to the Go language, you may be heard or seen the code about interface{} a lot in code snippets and tutorials. This can be very daunting seeing this at first. If you have used Java, PHP, or Python, you might know what interface is and how it can be helpful to … Read more

Golang Array: The Complete Guide

Golang programming language provides an array that is a fixed-size collection of elements of the same type. Golang Array A Golang array is a built-in data structure that can store the fixed-size sequential collection of items of the same type. The elements of an array are stored sequentially and can be accessed using their index. … Read more

How to Install Golang on Mac

Installing Golang on Mac is very easy. You can download the binary from the official website or install it using homebrew. Golang provides binary distributions for Mac OS X, Windows, and Linux. Then set up your Golang environment. You can download the Go source code and install it from the source using a different OS. … Read more

How to Serialize JSON String in Go

To serialize json string in Golang, you can use the “json.Marshal()” function. The “json.Marshal()” function returns the JSON encoding of the interface. Example package main import ( “encoding/json” “fmt” “log” ) // Define a struct to represent a person type Student struct { Name string `json:”name”` Age int `json:”age”` } func main() { // Create … Read more

What is the make() Function in Golang

Golang make() is a built-in “slice function used to create a slice”. The make() function takes three arguments: type, length, and capacity, and returns the slice. It creates an empty slice. The empty slices are those slices that contain the empty array reference. To create dynamically sized arrays, use Go’s make() function. The make() function … Read more

Golang strings.Contains() Method

Golang strings.Contains() is a built-in function that “checks whether the substring is within the string”. The Contains() function accepts two arguments and returns the boolean value, either true or false. To use Contains() function in Go, import the strings package and then call the contains() method and pass the two parameters: one is a source string, … Read more

Golang map: The Complete Guide

One of the most useful data structures in computer science is the hash table. Many hash table implementations exist with varying properties, but in general, they offer fast lookups, adds, and deletes. Go provides a built-in map type that implements a hash table. Go provides another essential data type named the map which maps unique … Read more

How to Convert int to string in Golang

Golang has a built-in package called strconv that provides functions that convert int to string. I have already covered how to convert string to int in this blog. Feel free to check it out. Golang int to string To convert Golang int to string, use the strconv.FormatInt(). The FormatInt() is a built-in Go function that returns … Read more

TypeCasting in Golang

Typecasting in Golang is a “way to convert the variable from one data type to another”. For example, if you want to save the long value into a simple integer, you can typecast long to int. Using the cast operator, you can convert the values from one type to another. In short, if you want … Read more