失败-预期的“包装",找到"EOF" [英] Go failing - expected 'package', found 'EOF'

查看:467
本文介绍了失败-预期的“包装",找到"EOF"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直很难在由vagrant提供支持的虚拟机中执行简单的golang程序. 这些是我的go env的相关字段:

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:

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

这是我要执行的程序(位于/usr/local/src/go/program中):

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")
}

这是我得到的输出:

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'

请考虑到这是一个完全伪造的程序.奇怪的是,它完全可以在不同的环境中工作. 我在这里想念什么?

Take into account that this is a completely fake program. The weird thing is that it totally works in a different environment. What am I missing here?

非常感谢!

推荐答案

GOROOTGOPATH都没有问题. go安装有时会失败,从而使整个过程变得不稳定(创建了文件,但完全为空).再次配置虚拟机时,go模块会检查文件是否存在.正如他们所做的那样,理所当然的是安装已经进行了.

The problem wasn't neither with GOROOT nor GOPATH. The go installation failed at some point, leaving the whole thing unstable ( files created but completely empty ). When provisioning the virtual machine again, the go module checked whether the files existed. As they did, it took by granted that the installation had already take place.

从头开始进行全新清洁安装即可解决问题.

A clean up and fresh installation from scratch solved the problem.

这篇关于失败-预期的“包装",找到"EOF"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆