Go failing - expected 'package', found 'EOF'

前端 未结 10 2104
感情败类
感情败类 2021-02-02 07:33

I\'ve been having a hard time trying to execute a simple golang program in a virtual machine powered by vagrant. These are the relevant fields of my go env:

相关标签:
10条回答
  • 2021-02-02 08:17

    In my case i was solve the problem by Using "VS Code" instead of default "text editor"

    The problem was some extra characters present in the file. Once we remove extra characters it will work.

    I wish it will solve to you also.

    0 讨论(0)
  • 2021-02-02 08:18

    As said by already suggested by Nico, When you create a new project and new main.go file this error will appear when the file is not saved. Save the file (ctrl + s) and this error will disappear in both mac & windows. I faced the same issue and just got it resolved by doing ctrl+S on the main.go file.

    0 讨论(0)
  • 2021-02-02 08:18

    As a new go user I came upon this answer looking for someone to tell me that I need to start my scripts with package main although my error was a little different,

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

    It's real obvious now, but hey, that's how it goes.

    0 讨论(0)
  • 2021-02-02 08:26

    Using VS Code for GO, and faced the same issue. Saving the file 'Ctrl+S' on Windows fixed the issue.

    Reference : Answered by Nico

    0 讨论(0)
  • 2021-02-02 08:27

    Just save the file first and than run the cammand.it is working.

    go run main.go

    0 讨论(0)
  • 2021-02-02 08:30

    For me, this also happened using Atom + Go Plus + Terminal Plus. The problem was that leading bracket was not on the "correct" line.

    NOTE: Go Plus warns about syntax upon save, but I had imported this file after creating it locally with VIM, so I was never presented with the lint errors...

    Error:

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

    Correct:

    package main
    import "fmt"
    func main() {
        fmt.Println("hello world")
    }
    
    0 讨论(0)
提交回复
热议问题