Just started to learn Go and I need map of string string, that I initialize literally.
mapa := map[string]string{ "jedan":"one", "dva":"two" } But compiler is complaining syntax error: need trailing comma before newline in composite literal
So I had to add coma after "two", or delete a new line and have } after last value for compiler to be happy
Is this intended behavior of code style?
EDIT: to be clear follwing will compile and work
mapa := map[string]string{ "jedan":"one", "dva":"two" } go version go1.4.2 darwin/amd64 Mac OSX 10.9.5
Go has semicolons, but you don't see them because they're inserted automatically by the lexer.
Semicolon insertion rules:
a semicolon is automatically inserted into the token stream at the end of a non-blank line if the line's final token is
- an integer, floating-point, imaginary, rune, or string literal
So this:
mapa := map[string]string{ "jedan": "one", "dva": "two" } is actually:
mapa := map[string]string{ "jedan": "one", "dva": "two"; // <- semicolon } Which is invalid Go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With