Language My Go Tutorial

Go: the blank identifier

The basic rule is: you declare it, you must use it. If you attempt to compile code with unused identifiers such as variables or named packages, the compilers will not be pleased and will fail compilation.

Go allows you to turn off this behavior using the blank identifier, represented by the _ (underscore) character. Any declaration or assignment that uses the blank identifier is not bound to any value and is ignored at compile time.

Muting unwanted function results

When a Go function call returns multiple values, each value in the return list must be assigned to a variable identifier. In some cases, however, it may be desirable to mute unwanted results from the return list while keeping others, as shown in the following call:

_, execFile := filepath.Split("/opt/data/bigdata.txt")