去代码构建错误,非标准导入" fmt"在标准包中,不允许导入循环

时间:2017-05-01 01:25:43

标签: linux ubuntu go

我已经工作了一段时间,本周末我想尝试部署一些服务器代码。当我在一些非常简单的代码上运行go build来测试Go是否正常工作时,我得到了这个错误:

can't load package: ($HOME)/go/src/goTest/main.go:4:2: non-standard 
import "fmt" in standard package "goTest"
import cycle not allowed
package goTest
        imports fmt
        imports errors
        imports runtime
        imports runtime/internal/atomic
        imports unsafe
        imports runtime

在我的〜/ .bashrc中我运行它来设置环境变量。

export GOPATH=/usr/local/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN

我的工作区位于$HOME/go,我的go安装位于默认/usr/local/go。任何帮助表示赞赏

main.go

package main

import (
    "fmt"
)

func main() {
    fmt.Println("test")
}

修改:go versiongo1.6 linux/amd64

2 个答案:

答案 0 :(得分:2)

设置ln -s $GOPATH/src/github.com/nubrozaref/goTest ~/goTest$GOPATH$GOROOT correctly。在这种情况下,它们应如下所示。

$GOBIN

此外,正确找到源代码。也许它应该在export GOPATH="$HOME/go" export GOROOT="/usr/local/go"

之下

(如果您使用较新版本的Go(&gt; = 1.8),则不必设置$GOPATH/src/github.com/<your id>/<repository name>/和其他人。Details here.

答案 1 :(得分:0)

我还没有看到这一点,但请尝试修复你的路径:

1)my-object='{"Code":"test"}'

2)export GOPATH=$HOME/go

3)export GOROOT=/usr/local/go

4)mkdir -p $GOPATH/src/github.com/nubrozaref/goTest

5)如果你想要:mv $GOPATH/src/goTest/ $GOPATH/src/github.com/nubrozaref/goTest

相关问题