Go Workspace 工作空间

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

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

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