简体   繁体   中英

Go get error when using throttled (“gopkg.in/throttled/throttled.v2”) library

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"

What you see is a Canonical import path introduced in Go 1.4 .

The syntax is a line comment in the package declaration, eg:

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, eg

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:

Go 1.4 Custom Import Path Checking - Design document

Canonical import paths in Golang

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM