In this post, we will discuss a useful idiom in Go that makes use of the fact
that receiving and sending on nil channels will always block:

// Create an uninitialized (nil) channel.varchchanstruct{}// Receiving on a nil channel blocks forever.<-ch// Sending on a nil channel will also block forever.ch<-struct{}{}

This might not seem very useful at first, and may have even
introduced bugs in your programs in the past (for example,
if you forget to initialize your channels with make before
you use them). However, this property can be leveraged in
a couple of clever ways, especially when you need to dynamically
disable a case in a select statement:

This post will briefly describe the differences between arrays and slices in Go. It assumes that you have completed
A Tour of Go and have consulted relevant sections of Effective Go and
the target audience is primarily newcomers to the Go programming language.

Arrays are fixed-length sequences of items of the same type.
Arrays in Go can be created using the following syntaxes:

Unlike in C/C++ (where arrays act like pointers) and Java (where arrays
are object references), arrays in Go are values. This has a
couple of important implications: (1) assigning one array to another
copies all of the elements, and (2) if you pass an array to a function,
it will receive a copy of the array (not a pointer or reference to it).

This post will briefly describe the differences between
the assignments and short variable declarations in Go.
It assumes that you have completed A Tour of Go
and have consulted relevant sections of Effective Go and
the target audience is primarily newcomers to the Go programming
language.

The assignment operator (=) is used to perform
assignments (i.e. to assign or reassign values to
already declared variables).

The short declaration operator (:=), on the other hand,
is used to perform short variable declarations),
which are shorthand for regular variable declarations but
without a specified type.

This post will briefly describe the differences between the
builtin new() and make() functions in Go.
It assumes that you have completed A Tour of Go
and have consulted relevant sections of Effective Go and
the target audience is primarily newcomers to the Go programming
language.

The builtin new(T) function
allocates “zeroed” storage for a new item of type
T and returns its address, a value of type *T.
In Go terminology, it returns a pointer to a newly
allocated zero value of type T. For example,
here are three different ways to create a pointer
p that points to a zeroed bytes.Buffer
value, each of which are equivalent:

// Allocate enough memory to store a bytes.Buffer value// and return a pointer to the value's address.varbufbytes.Bufferp:=&buf// Use a composite literal to perform allocation and// return a pointer to the value's address.p:=&bytes.Buffer{}// Use the new function to perform allocation, which will// return a pointer to the value's address.p:=new(bytes.Buffer)