我是 Go 的新手,我正在尝试制作一个程序来显示当前时间和其他一些内容:
// A terrible program.
package main
import (
"fmt"
"time"
)
// greeting returns a greeting with some info.
func greeting() string {
return "Hello flat world, the time is: " + time.Now().String()
}
func main() {
hotelName := "Trivag"
hotelName += "o"
fmt.Println(greeting())
fmt.Println("Hotel: " + hotelName)
}
当我尝试使用 go run
运行它时,它显示导入周期错误:
import cycle not allowed
package main
imports fmt
imports errors
imports runtime
imports internal/bytealg
imports internal/cpu
imports runtime
这些是我来自 go env
的 Go 环境变量:
GOARCH="amd64"
GOBIN="amd64"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/dullgo/go"
GORACE=""
GOROOT="/home/dullgo/.local/go"
GOTOOLDIR="/home/dullgo/.local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
编辑:.go 文件直接放在 ~/go 目录中。
最佳答案
该错误消息似乎是错误的:import cycle not allowed
消息应该以相同的包路径开始和结束。
请在 https://golang.org/issue/new 填写模板提交问题.
关于go - Go程序"Import cycle not allowed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57228990/