Go包导入找不到。

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

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包导入找不到。

但是当我进入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:

Go包导入找不到。

but when I go into the import section of the go file I get the following error:

Go包导入找不到。

Any ideas?

答案1

得分: 0

请看下面的完整工作会话,希望它能帮助你找出你的过程中出了什么问题。

  1. 确保我们使用的是最新的 Go 版本
$ go version
go version go1.18.1 linux/amd64
  1. 确保 GOPATH 未设置
$ echo $GOPATH

$
  1. 创建并初始化一个新模块
$ mkdir /tmp/example
$ cd /tmp/example
$ go mod init example.com/example
go: creating new go.mod: module example.com/example
$
  1. 编写测试程序
$ cat > main.go
package main

import (
	"fmt"

	"github.com/lestrrat-go/jwx/v2/jwk"
)

func main() {
	fmt.Println(jwk.Cache{})
}
$ 
  1. 下载所需的模块
$ 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
$
  1. 运行测试程序
$ 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.

  1. Make sure we are using a recent Go version
$ go version
go version go1.18.1 linux/amd64
  1. Make sure that GOPATH is unset
$ echo $GOPATH

$
  1. 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
$
  1. Write the test program
$ cat &gt; main.go
package main

import (
	&quot;fmt&quot;

	&quot;github.com/lestrrat-go/jwx/v2/jwk&quot;
)

func main() {
	fmt.Println(jwk.Cache{})
}
$ 
  1. 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
$
  1. Run the test program
$ go run example.com/example
{&lt;nil&gt;}
$ 

huangapple
  • 本文由 发表于 2022年5月1日 08:23:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/72073147.html
匿名

发表评论

匿名网友

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

确定