illegal rune literal
Problem : While writing out Go codes for tutorial today I came across this error message for the first time :
illegal rune literal
Diagnostic :
Based on the error information spitted out by the compiler. It pointed the fault to line 3:
import (
'fmt'
)
From the first glance everything seems to be ok and not sure why Go compiler refused to compile the code. Initially I taught it was a bug in Go compiler which reported the wrong line of code. But upon closer inspection ..... it has something to do with the single quote around 'fmt'
Solution :
Apparently, the compiler insisted on using double quote "
instead of '
to wrap around fmt
for all the packages to be imported properly.
Changing to "fmt"
solved the issue once and for all. The illegal rune literal
error just magically disappeared.
Sometimes, the error message spitted out by Go can be vague ... such as illegal rune literal
. Perhaps in future, the error message could be refined further to add more detailed description.
Reference :
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+13.5k Golang : Save(pipe) HTTP response into a file
+20.6k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+5.6k Golang : Humanize and Titleize functions
+5.6k Golang : Skip or discard items of non-interest when iterating example
+9.1k Golang : Convert file content to Hex
+4.9k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+13.7k Golang : Get all local users and print out their home directory, description and group id
+5.9k Golang : Pat multiplexer routing example
+10.1k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+14.9k Golang : Read integer from file into array
+10.3k Golang : Fuzzy string search or approximate string matching example
+5.2k Golang : Process non-XML/JSON formatted ASCII text file example