Kiran Kumar Panigrahi has Published 392 Articles

How to get the size of an array or a slice in Golang?

Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

Updated on 01-Nov-2021 07:47:24

932 Views

In case we want to get the size of an array or a slice, we can make use of the built-in len() function that Go provides us with.Example 1Let's first explore how to use the len function with an array. Consider the code shown below.package main import (   ... Read More

How to close a channel in Golang?

Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

Updated on 01-Nov-2021 07:45:20

3K+ Views

We can close a channel in Golang with the help of the close() function. Once a channel is closed, we can't send data to it, though we can still read data from it. A closed channel denotes a case where we want to show that the work has been done ... Read More

How to check if a string is a valid URL in Golang?

Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

Updated on 01-Nov-2021 07:41:23

5K+ Views

There are cases where we would want to know if the URL that we got from an http request in the form of a string is even valid or not. In such cases, one can use two functions that the net/url package of Go's standard library provides.Example 1The first basic ... Read More

What are WaitGroups in Golang?

Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

Updated on 01-Nov-2021 07:36:26

212 Views

There may be instances in Golang where the execution of different goroutines may cause unexpected behaviour. In such cases, we want to make sure that certain goroutines work in a predefined manner and the program waits for all goroutines that are launched from the main function to wait. To do ... Read More

How to use Mutex in Golang?

Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

Updated on 01-Nov-2021 07:33:12

431 Views

In order to understand why mutex in Go play a significant role to write better and accurate concurrent programs, we must first be aware of the concept called Race Conditions. Let's first understand what Race conditions are and how we can write a concurrent program that features a race condition ... Read More

How to use Tickers in Golang?

Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

Updated on 01-Nov-2021 07:28:20

7K+ Views

There are often cases where we would want to perform a particular task after a specific interval of time repeatedly. In Golang, we achieve this with the help of tickers.We can use them with goroutines as well so that we can run these tasks in the background of our application ... Read More

How to use Reflection in Golang?

Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

Updated on 01-Nov-2021 07:24:26

609 Views

Reflection in Golang is about getting to know the data types of the data that we are dealing with at runtime. There are often certain scenarios where we would want to know the data type of a certain variable that we are getting at runtime or something similar.With the help ... Read More

How to handle signals in Golang?

Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

Updated on 01-Nov-2021 07:21:04

1K+ Views

Before discussing signals and how to handle them, let's talk about a common scenario of creating a signal. A signal can be passed from the terminal, by either terminating the program with the help of CTRL+C or we can by default call the Exit() function that the os package provides ... Read More

How to use Timeouts in Golang

Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

Updated on 01-Nov-2021 07:16:42

3K+ Views

Timeouts play an important role when we don't want to wait for the output for some goroutines that are taking more time than what they should take. It should be noted that Go directly doesn't support timeouts, but we can implement them without any difficulty.Let's suppose we have a case ... Read More

Empty Slice vs. Nil Slice in Golang

Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

Updated on 01-Nov-2021 07:10:52

1K+ Views

In this article, we will see the differences and similarities that are there between a slice that is declared as an empty and a nil slice.Slices in Golang are used to store a sequence of elements. Slices can be expanded at any time and they are declared in the same ... Read More

Advertisements