Go failing - the expected "packet" found by "EOF",

It is not easy for me to try to run a simple golang program on a virtual machine that a tramp runs on. These are the relevant fields of my go env :

 GOARCH="amd64" GOPATH="/usr/local/src/go" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" 

This is the program I'm trying to execute (located in / usr / local / src / go / program):

 package program import ( "fmt" ) func main() { fmt.Print("Aloha") } 

This is the result I get:

 main.go:4:5: /usr/local/go/src/fmt/doc.go:1:1: expected 'package', found 'EOF' package runtime: /usr/local/go/src/runtime/alg.go:1:1: expected 'package', found 'EOF' 

Please note that this is a completely fake program. The strange thing is that it works completely in a different environment. What am I missing here?

Thanks a lot!

+15
source share
8 answers

The problem was not with GOROOT and GOPATH . At some point, the go installation failed, leaving everything unstable (files created but completely empty). When reinitializing a virtual machine, the go module checks to see if files exist. As this was done, it was required that the installation already take place.

Cleaning and fresh installation from scratch solved the problem.

+10
source

Using VS Code for GO, I ran into the same problem. Saving the file "Ctrl + S" on Windows fixed the problem.

Link: Nico

+29
source

This usually happens when you have a file, for example. foo_test.go empty or without package declaration.

+14
source

For me, this also happened with Atom + Go Plus + Terminal Plus. The problem was that the lead bracket was not on the β€œright” line.

NOTE : Go Plus warns about syntax when saving, but I imported this file after I created it locally using VIM, so I never got a lint error ...

Error:

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

Right:

 package main import "fmt" func main() { fmt.Println("hello world") } 
+2
source

Just save the file and then run cammand.it to work.

go run main.go

+1
source

As Niko already said, when creating a new project and a new main.go file, this error will appear when the file is not saved. Save the file (Ctrl + S), and this error will disappear as in Mac & windows. I ran into the same problem and just solved it by doing Ctrl + S in main.go.

0
source

As a new user, I came up with this answer, looking for someone to tell me that I need to run my scripts using package main , although my error was a bit different.

... expected 'package', found 'import'

Now this is obvious, but hey, how's it going.

-1
source

a separate Go file in the same package, did not have a "main package" declaration, and because of this, the console threw errors when launching the Main GO file .

When the main package declaration was provided in another Go file, the error stopped showing.

-1
source

All Articles