我正在寻找go.mod的replace指令:
https://thewebivore.com/using-replace-in-go-mod-to-point-to-your-local-module/
module github.com/pselle/foo
replace github.com/pselle/bar => /Users/pselle/Projects/bar
require (
github.com/pselle/bar v1.0.0
)
在团队中工作时,这是很愚蠢的,因为url是绝对的,除了您自己的机器外,其他任何机器都无法使用。
有没有一种方法可以使用环境变量或相对路径来指定替换指令?像这样:
replace github.com/pselle/bar => $GOPATH/src/github.com/pselle/bar
要么
replace github.com/pselle/bar => ./github.com/pselle/bar
当PWD更改时,使用相对路径非常可怕,带有env var的绝对路径会更好。
这应该可以回答您的问题:
https://stackoverflow.com/a/55534126/12834955
Env变量不起作用,但是您可以使用相对于固定位置(模块的根)的相对路径。从答案中可以看出:
您为replace指令指定的路径必须是相对于模块根目录的绝对路径或相对路径。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句