获取缺失的包 golang.org/x/text/encoding/unicode 的导入循环。

huangapple go评论90阅读模式
英文:

Get missing package golang.org/x/text/encoding/unicode import cycle

问题

我正在尝试复现这个Go问题,但无法轻松构建他们的示例:

$ cat main.go
package main
import ("fmt"; "golang.org/x/text/encoding/unicode")
func main() {
    res, err := unicode.UTF16(unicode.BigEndian, unicode.UseBOM).NewDecoder().String(" ")
    fmt.Println(res, err)
}
$ go mod init golang.org/x/text/encoding/unicode
go: creating new go.mod: module golang.org/x/text/encoding/unicode
go: to add module requirements and sums:
    go mod tidy
$ go mod tidy 1>/dev/null 2>/dev/null
$ go build main.go
package command-line-arguments
    imports golang.org/x/text/encoding/unicode
    imports golang.org/x/text/encoding/unicode: import cycle not allowed
英文:

I'm trying to reproduce this go issue, but can't easily build their example:

$ cat main.go
package main
import ("fmt"; "golang.org/x/text/encoding/unicode")
func main() {
	res, err := unicode.UTF16(unicode.BigEndian, unicode.UseBOM).NewDecoder().String(" ")
	fmt.Println(res, err)
}
$ go mod init golang.org/x/text/encoding/unicode
go: creating new go.mod: module golang.org/x/text/encoding/unicode
go: to add module requirements and sums:
	go mod tidy
$ go mod tidy 1>/dev/null 2>/dev/null
$ go build main.go
package command-line-arguments
	imports golang.org/x/text/encoding/unicode
	imports golang.org/x/text/encoding/unicode: import cycle not allowed

答案1

得分: 4

我怀疑你不应该使用与你的导入相同的名称来初始化项目的模块名称。

尝试使用以下命令:

go mod init test
英文:
go mod init golang.org/x/text/encoding/unicode

I suspect you should not initialise a project with a module name using the same name as your import.

Try:

go mod init test

huangapple
  • 本文由 发表于 2021年7月19日 14:01:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/68435717.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定