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 ...

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>
本文总阅读量 次 本站总访问量 次 本站总访客数