An online example of Go I am following has the following syntax for a map type as a parameter in a function:
func (contact *Contact) Validate() (map[string] interface{}, bool) {
What does the space between map[string] and interface mean? I can't find any other examples defining a map with a space there.
It doesn't mean anything. It doesn't matter if you leave space(s) there or not, the code is the same. Always use gofmt
to avoid dis-ambiguity.
Tokens form the vocabulary of the Go language. There are four classes: identifiers, keywords, operators and punctuation, and literals. White space, formed from spaces (U+0020), horizontal tabs (U+0009), carriage returns (U+000D), and newlines (U+000A), is ignored except as it separates tokens that would otherwise combine into a single token. Also, a newline or end of file may trigger the insertion of a semicolon. While breaking the input into tokens, the next token is the longest sequence of characters that form a valid token.
The map type: map[string]interface{}
is made up of tokens, and a white space at the position in question: map[string] interface{}
is simply ignored because the tokens it separates (]
and interface
would not combine into a single token if the space wouldn't be there.