模块声明为 X 但需要为 Y

kjq*_*7bd 6 go go-modules go-xorm

我正在尝试grafana/grafana/pkg/tsdb在我的模块中使用包。我不认为这个问题是 grafana 特有的,但它是这样的:

$ go get -u github.com/grafana/grafana/pkg/tsdb
go: finding github.com/inconshreveable/log15 latest
go: finding github.com/go-macaron/session latest
go: finding golang.org/x/oauth2 latest
go: finding github.com/teris-io/shortid latest
go: github.com/grafana/grafana/pkg/tsdb imports
        github.com/go-xorm/core: github.com/go-xorm/core@v0.6.3: parsing go.mod:
        module declares its path as: xorm.io/core
                but was required as: github.com/go-xorm/core
Run Code Online (Sandbox Code Playgroud)

它说包tsdb将 xorm 导入为github.com/go-xorm/core,但模块将自身声明为xorm.io/core.

查看 Grafana 的go.mod文件,它正在使用github.com/go-xorm/core并转到github.com/go-xorm/core,它说该项目现已存档......它的go.mod文件确实将自己声明为xorm.io/core......

以及有关如何解决此问题的建议?

max*_*axm 3

编辑:我也很幸运只使用了稍旧的版本:

go get github.com/grafana/grafana/pkg/tsdb@6.6.1
Run Code Online (Sandbox Code Playgroud)

我尝试了替换,有时可以工作:

module foo

replace github.com/go-xorm/core => xorm.io/core v0.6.2

go 1.13

require (
...
Run Code Online (Sandbox Code Playgroud)

但我收到类型错误。

幸运的是,看起来有一个 PR 可以解决这个问题:https://github.com/grafana/grafana/pull/22376