【发布时间】:2020-02-04 02:35:34
【问题描述】:
我正在尝试创建一个微服务应用程序,这取决于我的 net 模块,其中包含一般错误(因此我不必在我的所有模块中“复制”它们)。
问题是由于某种原因它能够找到模块,然后告诉我模块没有包(net 模块没有main.go 文件,因为它只是一组在其他项目中使用的文件)
go: finding github.com/USERNAME/net latest
build github.com/USERNAME/micro-helix: cannot load github.com/USERNAME/net: module github.com/USERNAME/net@latest found (v0.0.0-20191209010811-97a65ac0928c), but does not contain package github.com/USERNAME/net
这是包含所有必要要求的go.mod 文件(就我而言):
module github.com/USERNAME/micro-helix
go 1.13
require (
github.com/USERNAME/net v0.0.0-20191209010811-97a65ac0928c
github.com/USERNAME/service v0.0.0-20191209005400-57ee0eb02082
github.com/golang/protobuf v1.3.2
github.com/hashicorp/consul/api v1.3.0 // indirect
github.com/micro/go-micro v1.17.1
github.com/micro/go-plugins v1.5.1 // indirect
github.com/nats-io/nats-streaming-server v0.16.2 // indirect
github.com/nats-io/stan.go v0.5.2 // indirect
github.com/nicklaw5/helix v0.5.4
github.com/spf13/viper v1.5.0 // indirect
)
net 模块的go.mod 文件很简单:
module github.com/USERNAME/net
go 1.13
如果您需要任何进一步的说明,我在这里提供。我知道这可能是一些新手错误(配置错误),但这是我第一周真正尝试用 Go 写东西。
更新 #1
这是github.com/USERNAME/net模块的结构
/-
errors/
- error.go // github.com/USERNAME/net/errors
- code.go // github.com/USERNAME/net/errors
proto/
- error.pb.go // github.com/USERNAME/net/proto
- response.pb.go // github.com/USERNAME/net/proto
errors.proto
go.mod // module github.com/USERNAME/net
response.proto
【问题讨论】:
-
module
net的go文件声明什么包名? -
@BurakSerdar 我已经用
net模块的结构更新了这个问题,我希望它有帮助,如果没有,请你详细说明你的问题,因为我有点困惑 -
你是怎么得到这个错误的?你在跑去拿吗?还是您在 net 中导入了其中一个包并运行 go build?
-
@BurakSerdar 首先,我编写了
net模块并将其推送到github,然后我转移到另一个使用net的应用程序,并且我已经安装了它使用go get -u github.com/USERNAME/net,问题是,第二个应用程序在导入文件时非常好(我可以Shift + RClick Goland 中的文件名并转到net实现),但构建失败并出现错误问题 -
这个错误意味着你在某个地方有一个
import "github.com/USERNAME/net",由于github.com/USERNAME/net不包含 Go 源文件,所以它不会工作。我会在你所有的源代码中搜索github.com/USERNAME/net并确保你没有尝试直接在任何地方导入它,你只是在它下面导入包。
标签: go go-modules