私有Go项目和超越Go 1.13的GOPATH [英] Private Go projects and GOPATH beyond go 1.13
问题描述
我的项目依赖于一些无法获取的私有Go项目.以前我只是将其放在GOPATH中的适当位置(例如, $ GOPATH/src/mycompany/mylib/lib.go
),生活是美好的.也就是说,我不需要在其中应用任何花哨的技术性技巧,
My project depends on some private Go projects that are not go-gettable. Previously I just put then in the GOPATH at proper places (e.g., $GOPATH/src/mycompany/mylib/lib.go
), and life was good. I.e., I don't need to apply any fancy techy hacks in,
我可以完成我的工作.
现在,在超过1.13的情况下,仍然存在任何低技术含量的解决方案,只要将其放在GOPATH下的适当位置即可解决此问题?
Now, with go beyond 1.13, is there still any low tech solution, as simple as putting it at proper place under GOPATH to such problem?
谢谢
推荐答案
如果要使用 $ GOPATH
方式,则此方法仍适用于 go1.14.1 >:
If you want to go with the $GOPATH
way, then this is still working on go1.14.1:
您可以将两个项目(不使用gomodules)放入GOPATH中:
You can put both projects (not using gomodules) inside your GOPATH:
- 项目
foo
在GOPATH/src/foo/
下 - 项目,我们的库
greeting
在GOPATH/src/myfancycompany/greeting/
下
我们的目标是 foo
将导入 greeting
.
然后 foo/main.go
看起来像这样:
package main
import "myfancycompany/greeting"
func main() {
println("How to greet?")
greeting.English()
}
我们的库 myfancycompany/greeting/greeter.go
如下所示:
package greeting
func English() {
println("hi, i am boo")
}
然后 go构建main.go
并运行 ./main
:
~/go/src/foo$ ./main
How to greet?
hi, i am boo
这篇关于私有Go项目和超越Go 1.13的GOPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!