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
+18.7k Golang : Find IP address from string
+7.1k Golang : Gargish-English language translator
+12.5k Golang : Search and extract certain XML data example
+16.5k Golang : Convert slice to array
+12.4k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+9.7k Golang : How to generate Code 39 barcode?
+13.8k Golang : Check if an integer is negative or positive
+11.1k Golang : Create S3 bucket with official aws-sdk-go package
+12.4k Golang : Encrypt and decrypt data with x509 crypto
+12.4k Golang : Validate email address
+9.3k Golang : does not implement flag.Value (missing Set method)
+6.9k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?