0

I'm trying to run the hello world from golang in this link But when I run go install, I'm getting this error:

hello.go:1:1: illegal character U+0023

This is my hello.go

package main    
import "fmt"
func main() {
  fmt.Printf("hello, world")
}

I'm using Mac OS El Captain What is wrong?

Filipe Ferminiano
  • 8,373
  • 25
  • 104
  • 174
  • 3
    You have a '#' somewhere in your code which is invalid. – gan_ Jul 10 '16 at 16:03
  • 1
    Use this link to verify your terminal's UTF-8 settings http://stackoverflow.com/questions/4606570/os-x-terminal-utf-8-issues – dmitryro Jul 10 '16 at 16:05

2 Answers2

5

you have '#' in first line of your code which is invalid,
see this test sample code:

# just remove this line
package main

import "fmt" 

func main() {
    fmt.Println("Hello World!") 
}

this will give this error:

hello.go:1:1: illegal character U+0023 '#'

but if you remove lines containing # it works fine:

package main

import "fmt"

func main() {
    fmt.Println("Hello World!")
}

it seems your IDE is not for Go. See:
https://github.com/visualfc/liteide
https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins
http://www.distilnetworks.com/setup-go-golang-ide-for-mac-os-x/

-1

I had the same problem but had no '#' in the source whatsoever. My LOCALE was set correctly. My problem was that I created the source via cut and paste from:

https://medium.com/@singh.shreya8/how-to-install-go-lang-in-ubuntu-14-04-ubuntu-16-04-ubuntu-18-04-linux-19e4c8aad4b8

The problem was solved by deleting and retyping the double quotes in the source. Just for grins I tried a cut and paste from:

https://golang.org/doc/code.html

and had no problems. Go figure.

Ed Bell
  • 11