Golang中不包含github.com/ProtonMail/go-crypto包的问题
Golang中不包含github.com/ProtonMail/go-crypto包的问题 关于:go-crypto 模块 - github.com/ProtonMail/go-crypto - Go Packages 当我尝试将其导入我的项目时,出现了以下情况:
~/Documents/$ go get github.com/ProtonMail/go-crypto
go: added github.com/ProtonMail/go-crypto v0.0.0-20220517143526-88bb52951d5b
~/Documents/$ go mod tidy
go: finding module for package github.com/ProtonMail/go-crypto
circle imports
github.com/ProtonMail/go-crypto: module github.com/ProtonMail/go-crypto@latest found (v0.0.0-20220517143526-88bb52951d5b), but does not contain package github.com/ProtonMail/go-crypto
有什么建议吗?
更多关于Golang中不包含github.com/ProtonMail/go-crypto包的问题的实战教程也可以访问 https://www.itying.com/category-94-b0.html
1 回复
更多关于Golang中不包含github.com/ProtonMail/go-crypto包的问题的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html
这个问题通常是因为 go-crypto 模块使用了子包结构,你需要导入具体的子包而不是根模块。根据官方文档,你应该导入类似 github.com/ProtonMail/go-crypto/openpgp 这样的具体子包。
以下是解决方案:
// 错误导入方式
import "github.com/ProtonMail/go-crypto" // 这会失败
// 正确导入方式 - 导入具体的子包
import (
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/ProtonMail/go-crypto/ed25519"
// 或者其他你需要的具体子包
)
清理并重新获取依赖:
# 首先移除错误的依赖
go mod edit -droprequire=github.com/ProtonMail/go-crypto
# 然后获取你实际需要的子包
go get github.com/ProtonMail/go-crypto/openpgp
# 或者如果你需要多个子包
go get github.com/ProtonMail/go-crypto/...
# 最后运行 tidy
go mod tidy
检查你的 go.mod 文件,确保它看起来像这样:
require github.com/ProtonMail/go-crypto v0.0.0-20220517143526-88bb52951d5b
在你的代码中使用示例:
package main
import (
"fmt"
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/ProtonMail/go-crypto/openpgp/packet"
)
func main() {
// 使用 openpgp 包
config := &packet.Config{
DefaultCipher: packet.CipherAES256,
}
// 你的代码逻辑
fmt.Println("PGP config created")
}
如果你需要特定的功能,查看官方文档确定需要导入的具体子包路径。常见的子包包括:
github.com/ProtonMail/go-crypto/openpgpgithub.com/ProtonMail/go-crypto/ed25519github.com/ProtonMail/go-crypto/rsagithub.com/ProtonMail/go-crypto/eax

