Go工作空间的最佳做法是什么? [英] Whats a good best practice with Go workspaces?
问题描述
我刚刚开始学习Go,阅读现有代码以了解其他人如何做。在这样做的过程中,使用工作区,特别是涉及到项目的依赖关系时,似乎遍布整个地方。
什么(或者是否存在)围绕使用单个或多个Go工作空间(即$ GOPATH的定义)在处理各种Go项目时使用的常见最佳做法?我是否应该期待拥有一个Go工作空间,就像我所有项目的中央代码库一样,或者在我开始处理这些项目时设置$ GOPATH(有点像python我认为有一个 $ GOPATH
更容易一些,每个项目,这样你可以为不同的项目使用相同的软件包版本,并根据需要更新软件包。
I'm just getting into learning Go, and reading through existing code to learn "how others are doing it". In doing so, the use of a go "workspace", especially as it relates to a project's dependencies, seems to be all over the place.
What (or is there) a common best practice around using a single or multiple Go workspaces (i.e. definitions of $GOPATH) while working on various Go projects? Should I be expecting to have a single Go workspace that's sort of like a central repository of code for all my projects, or explicitly break it up and set up $GOPATH as I go to work on each of these projects (kind of like a python virtualenv)?
I think it's easier to have one $GOPATH
per project, that way you can have different versions of the same package for different projects, and update the packages as needed.
With a central repository, it's difficult to update a package as you might break an unrelated project when doing so (if the package update has breaking changes or new bugs).
这篇关于Go工作空间的最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!