英文:
Go get error when using throttled ("gopkg.in/throttled/throttled.v2") library
问题
当我尝试使用go get
命令安装throttled时:
go get "github.com/throttled/throttled"
我遇到了以下错误:
无法加载包:包github.com/throttled/throttled的代码在目录/Users/litanhua/GoglandProjects/cloudstorage/src/github.com/throttled/throttled中期望导入"gopkg.in/throttled/throttled.v2"
英文:
When I attempt to install throttled using go get
command:
go get "github.com/throttled/throttled"
I get the error:
can't load package: package github.com/throttled/throttled: code in directory /Users/litanhua/GoglandProjects/cloudstorage/src/github.com/throttled/throttled expects import "gopkg.in/throttled/throttled.v2"
答案1
得分: 4
你看到的是Go 1.4中引入的规范导入路径。
语法是在包声明中的一行注释,例如:
package pdf // import "rsc.io/pdf"
如果指定了规范导入路径,你只能使用其规范导入路径导入和获取该包,该路径可能与托管服务的URL不同,就像你的情况一样。
你所提到的包使用了规范导入路径,请参见github.com/throttled/throttled/doc.go:
// Package throttled implements rate limiting access to resources such
// as HTTP endpoints.
package throttled // import "gopkg.in/throttled/throttled.v2"
规范导入路径由go工具强制执行。删除标记规范导入路径的注释是解决问题的一个非常糟糕的方法。
只需按照规范导入路径进行获取:
go get gopkg.in/throttled/throttled.v2
然后当然可以使用/引用规范导入路径的包,例如:
import "gopkg.in/throttled/throttled.v2"
这也在throttled的主页上有说明,安装部分:
> throttled使用gopkg.in进行语义化版本控制:go get gopkg.in/throttled/throttled.v2
有关该主题的更多帖子:
英文:
What you see is a Canonical import path introduced in Go 1.4.
The syntax is a line comment in the package declaration, e.g.:
package pdf // import "rsc.io/pdf"
If canonical import path is specified, you are only allowed to import and go-get the package using its canonical import path, which may be different from the hosting service URL, such as your case.
The package you refer to uses canonical import path, see github.com/throttled/throttled/doc.go:
// Package throttled implements rate limiting access to resources such
// as HTTP endpoints.
package throttled // import "gopkg.in/throttled/throttled.v2"
Canonical import paths are enforced by the go tool. Deleting the comments denoting the the canonical import paths is a really bad way to go about solving your problem.
Simply go get by the canonical import path:
go get gopkg.in/throttled/throttled.v2
And then of course use / refer to the packages by the canonical import path, e.g.
import "gopkg.in/throttled/throttled.v2"
This is also noted on throttled's home page, Installation section:
> throttled uses gopkg.in for semantic versioning: go get gopkg.in/throttled/throttled.v2
Further posts about the topic:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论