Useful Go language Tips & tricks

Retract Go Module Versions in Go 1.16
Learn how to retract Go module versions in Go 1.16
foreach loop in Go
There's no foreach loop in Golang.However we can replicate foreach loop behaviour using for loop in Go
How to Check for an Empty String in Go
There are two ways we can check for an empty string in Go language.1. Comparing with empty string. 2. Checking the length of the string.
How to Make HTTP POST JSON request in Go
Golang's net/http package is used to make HTTP requests in Go.The HTTP POST method used to send data to a server and in most of the cases the data will be in JSON format.
How to Write multiline strings in Go
To create or write multiline strings in Go, use the backtick (`) character while declaring or assigning value to the string.
Best way to Concatenate Strings in Go
To concatenate string in Go (aka Golang) we can use strings.Builder and bytes.Buffer types.
How to Concatenate Two Slices in Go
Using golang's `append()` function we can concatenate two slices in Go.
How to Concatenate Two strings in Go
There three simple ways to concatenate two strings in Go language 1. Using + operator 2. Using string append += operator. 3. Using Sprintf()
How to Join/Concatenate Strings with a Separator or Delimiter in Go
To join or concatenate strings with a separator or delimiter in Go, use strings.Join() method
Check if a map contains a key in Go
To check if a map contains a key in Go, follow the below steps.1. Index the map with the given key. 2. When we index a map in Go, we will get two return values.3. First return value contains the value and the second return value is a boolean that indicates if the key exists or not
Embed Files in Go using "embed package" in go 1.16 version
In Go 1.16 version, using package embed, we can easily embed files in Go programs.
Convert a String To Byte Array or Slice in Go
To convert a string to byte array or slice in Go language use []byte(string)
How to Convert an int to string (int32 & int64) in Go
To Convert an int to string in Go use strconv.Itoa()(int32 to string) and strconv.FormatInt()(int64 to string) functions which are part of Go's strconv package
4 methods to check or find type of an Object or Variable in Go
To check or find the type of variable or object in Go language, we can use %T string format flag, reflect.TypeOf, reflect.ValueOf.Kind functions.And another method is to use type assertions with switch case