go - Go程序"Import cycle not allowed"错误

标签 go

我是 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/

相关文章:

go - Rob Pike 在 Go 中的 "the synchronization nature of the channels"是什么意思?

安装 go 工具的 go 模块

go - 使用 gorm Golang lib 构建自定义查询

csv - 有没有一种方法可以将csv文件中的每一行填充到不同的文本文件中?

image - 如何使用 go 脚本在 Google-Cloud-Storage 中获取我的图像(base64)

logging - 使用 io.Multiwriter 跨包/子包创建日志

go - Go中的Flags解释

templates - 在不使用变量的情况下从 Golang 模板中的 map 获取所有键

list - 如何在 Go 中获取映射键的排序列表?

json - 将二进制数据 blob 发送到 dynamodb 时出错