Mukul Latiyan has Published 322 Answers

Sorting in Golang with sort Package

Mukul Latiyan

Mukul Latiyan

Updated on 22-Feb-2022 05:40:50

The standard library of Golang provides a package that we can use if we want to sort arrays, slices, or even custom types. In this article, we will discover three main functions that we can use if we want to sort a slice in Golang. We will also see how ... Read More

How to use iota in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 22-Feb-2022 05:32:09

Iota in Go is used to represent constant increasing sequences. When repeated in a constant, its value gets incremented after each specification. In this article, we will explore the different ways in which we can use iota in Go.Let's first consider a very basic example, where we will declare multiple ... Read More

How to parse Date strings in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 22-Feb-2022 05:28:17

When it comes to parsing Date strings in Go, we can use the Parse function that is provided by the time package. In Go, we don't use codes like most other languages to represent the component parts of a date/time string. Instead, Go uses the mnemonic device - standard time ... Read More

Anonymous goroutines in Golang

Mukul Latiyan

Mukul Latiyan

Updated on 22-Feb-2022 05:22:37

In order to be able to understand the anonymous goroutines, we must be aware of the existence of anonymous functions and goroutines. We will first explore the anonymous functions that are the real reason behind the motivation of anonymous goroutines and then we will learn a little about what goroutines ... Read More

How to check if a string contains a substring in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 08:16:10

We know that substrings are a contiguous sequence of characters in a string, and in order to check whether a string contains a substring, we have two options available.The first approach is to use a built-in function called Contains() and the second approach is to make use a self-written logic ... Read More

How to compare slices, structs and maps in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 08:09:20

The reflect package in Go provides a very important function called DeepEqual() which can be used to compare composite types. The DeepEqual() function is used when we want to check if two data types are "deeply equal".Comparing slicesExample 1Consider the code shown belowpackage main import (    "fmt"    "reflect" ... Read More

How to check if a key exists in a map in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 07:32:37

We know that maps in Go contain key-value pairs. There are often instances where we would want to know that a certain key exists in a map or not, in such cases, we have two options available.The first approach is very naive, as in this approach, we basically iterate over ... Read More

How to search and replace texts in a string in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 07:28:20

We often want to replace certain strings or all the strings that match a pattern with some other string. In order to do that in Golang, we can either use the native functions that the strings package of Go's standard library provides us with or we can write the logic ... Read More

How to read CSV files in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 07:25:43

To read a CSV file in Go, the first thing that we need to make use of is the encoding/csv package that the Go standard library provides us with. The encoding/csv package contains different functions and methods that can be used when we want to read data from a CSV ... Read More

How to check if a slice contains an element in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 07:21:46

Many languages do provide a method similar to indexOf() where one can find the existence of a particular element in an array-like data structure. However, in Golang, there's no such method and we can simply implement it with the help of a for-range loop.Let's suppose we have a slice of ... Read More

Advertisements