Go Workspace 工作空间

发布时间: 更新时间: 总字数:241 阅读时间:1m 作者: IP属地: 分享 复制网址

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 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
  • go.work 文件
$ 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>

参考

  1. https://go.googlesource.com/proposal/+/master/design/45713-workspace.md
  2. https://pkg.go.dev/cmd/go@go1.18beta1#hdr-Workspace_maintenance
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数