英文:
Go package import cant be found
问题
我是你的中文翻译助手,以下是翻译的内容:
我是Go语言的新手,尝试导入在这里找到的jwx包。使用以下示例代码。在Windows上,我在源代码的根目录中执行以下命令。
go get github.com/lestrrat-go/jwx
go get github.com/lestrrat-go/jwx/jwk
执行"get go"命令时出现以下情况:
但是当我进入go文件的导入部分时,出现以下错误:
有什么想法吗?
英文:
I'm new to Go and trying to import the jwx package found here. Using the following sample code. On Windows, I execute the following command in the root of my source.
go get github.com/lestrrat-go/jwx
go get github.com/lestrrat-go/jwx/jwk
The command "get go" passes:
but when I go into the import section of the go file I get the following error:
Any ideas?
答案1
得分: 0
请看下面的完整工作会话,希望它能帮助你找出你的过程中出了什么问题。
- 确保我们使用的是最新的 Go 版本
$ go version
go version go1.18.1 linux/amd64
- 确保 GOPATH 未设置
$ echo $GOPATH
$
- 创建并初始化一个新模块
$ mkdir /tmp/example
$ cd /tmp/example
$ go mod init example.com/example
go: creating new go.mod: module example.com/example
$
- 编写测试程序
$ cat > main.go
package main
import (
"fmt"
"github.com/lestrrat-go/jwx/v2/jwk"
)
func main() {
fmt.Println(jwk.Cache{})
}
$
- 下载所需的模块
$ go mod tidy
go: downloading github.com/lestrrat-go/jwx/v2 v2.0.0
go: downloading github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1
go: downloading github.com/lestrrat-go/blackmagic v1.0.1
go: downloading github.com/lestrrat-go/httprc v1.0.1
go: downloading github.com/lestrrat-go/iter v1.0.2
go: downloading github.com/lestrrat-go/option v1.0.0
go: downloading github.com/goccy/go-json v0.9.7
go: downloading golang.org/x/crypto v0.0.0-20220214200702-86341886e292
go: downloading github.com/lestrrat-go/httpcc v1.0.1
go: downloading github.com/stretchr/testify v1.7.1
go: downloading gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
go: downloading github.com/davecgh/go-spew v1.1.0
go: downloading github.com/pmezard/go-difflib v1.0.0
$
- 运行测试程序
$ go run example.com/example
{<nil>}
$
英文:
Have a look at a fresh full working session below, hope it can help you find what it's wrong with your procedure.
- Make sure we are using a recent Go version
$ go version
go version go1.18.1 linux/amd64
- Make sure that GOPATH is unset
$ echo $GOPATH
$
- Create and initialize a new module
$ mkdir /tmp/example
$ cd /tmp/example
$ go mod init example.com/example
go: creating new go.mod: module example.com/example
$
- Write the test program
$ cat > main.go
package main
import (
"fmt"
"github.com/lestrrat-go/jwx/v2/jwk"
)
func main() {
fmt.Println(jwk.Cache{})
}
$
- Download required modules
$ go mod tidy
go: downloading github.com/lestrrat-go/jwx/v2 v2.0.0
go: downloading github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1
go: downloading github.com/lestrrat-go/blackmagic v1.0.1
go: downloading github.com/lestrrat-go/httprc v1.0.1
go: downloading github.com/lestrrat-go/iter v1.0.2
go: downloading github.com/lestrrat-go/option v1.0.0
go: downloading github.com/goccy/go-json v0.9.7
go: downloading golang.org/x/crypto v0.0.0-20220214200702-86341886e292
go: downloading github.com/lestrrat-go/httpcc v1.0.1
go: downloading github.com/stretchr/testify v1.7.1
go: downloading gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
go: downloading github.com/davecgh/go-spew v1.1.0
go: downloading github.com/pmezard/go-difflib v1.0.0
$
- Run the test program
$ go run example.com/example
{<nil>}
$
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论