In Go, we are often returning zero values. Idiomatic Go encourages the use of guard clauses, and guard clauses necessitate the need to return early. When returning early with an error, by convention all other return values should be zero values.

I ran a quick bit of code to show some of the differences between nil and empty slices: As you can see there are some similarities between nil and empty slices: They differ in the following ways: Generally speaking, prefer nil.

When we just need to return an empty slice nil will work great in practically all cases.

Related Articles