我在Golang中使用wgo进行依赖关系管理(虽然我认为wgo与此无关),wgo有类似的文件夹结构
project/
.gocfg/
gopaths
vendor.json
vendor/
src/
github.com_or_whatever/我有一个自己编写的库,它在导出的方法中使用nsq-go类型:
func AddNsqSubscription(
topic, channel string,
handler nsq.Handler,
config *nsq.Config) error { }这个库名为messi,我导入的nsq-go类似于"messi/vendor/src/github.com/bitly/go-nsq"
当我试图在另一个项目中使用这个库时,问题就出现了。例如,在一个名为scribe的项目中,我有以下代码(注意导入):
import (
"scribe/vendor/src/github.com/bitly/go-nsq"
"scribe/vendor/src/messi"
)
//...
nsqHandler := nsq.HandlerFunc(func(message *nsq.Message) error {
msgHandler(MessiMessage{message})
return nil
})
return messi.AddNsqSubscription(destination, subdestination, nsqHandler, nsq.NewConfig())当我go build时,将返回以下错误:
"scribe/vendor/src/github.com/bitly/go-nsq".HandlerFunc)不能使用 nsqHandler (在messi.AddNsqSubscription参数中键入"messi/vendor/src/github.com/bitly/go-nsq".Handler:"scribe/vendor/src/github.com/bitly/go-nsq".HandlerFunc不实现"messi/vendor/src/github.com/bitly/go-nsq".Handler (错误类型为HandleMessage方法)) HandleMessage("scribe/vendor/src/github.com/bitly/go-nsq".Message) 有错误 HandleMessage("messi/vendor/src/github.com/bitly/go-nsq".Message) 需要错误
为什么?我真的不知道发生了什么。导入的代码go-nsq完全相同,但golang希望这段代码来自同一个文件夹?
我做错了什么?
发布于 2015-08-12 15:20:39
Go中的包由完整导入路径标识,而不是按名称标识。
例如,在标准库中,有两个不同的包,它们同名为template,但导入路径不同:text/template和html/template。
您应该确保使用相同的路径导入go-nsq包。
https://stackoverflow.com/questions/31969088
复制相似问题