golang多个子项目可以使用工作空间(workspace)组织在一起。
介绍
将多个子项目组成一个工作空间,解决相互依赖的问题。
使用
go 1.8(包括)之后的版本
help
Usage:
go work <command> [arguments]
The commands are:
edit edit go.work from tools or scripts
init initialize workspace file
sync sync workspace build list to modules
use add modules to workspace file
$ go help work
…
go.work files…
go 1.18
use ../foo/bar
use ./baz
replace example.com/foo v1.2.3 => example.com/bar v1.4.5
…
use (
../foo/bar
./baz
)
…
Usage:
go work <command> [arguments]
The commands are:
edit edit go.work from tools or scripts
init initialize workspace file
sync sync workspace build list to modules
use add modules to workspace file
Use “go help work ” for more information about a command.
demo
go work init
mkdir subproj1
cd subproj1
go mod init subproj1
cd ..
go work use ./subproj1
$ cat go.work
go 1.19
use ./subproj1
gotip
go 1.8 之前版本
# install
go install golang.org/dl/gotip@latest
gotip download dev.cmdgo
# create go.work
gotip mod initwork subproj1 subproj2 ...
# build
gotip build <path-to-cmd>