创建 myworkspace 主项目
mkdir myworkspace
cd myworkspace
创建 common 子项目
mkdir common && cd common
go mod init common
vim common.go
myworkspace/common/common.go
package common
import "fmt"
func Dosomething() {
fmt.Println("do something...")
}
创建 myproject_1 子项目
cd .. && mkdir myproject_1 && cd myproject_1
go mod init myproject_1
vim main.go
myworkspace/myproject_1/main.go
package main
import "common"
func main() {
common.Dosomething()
}
// package common is not in GOROOT
初始化multi-module workspaces 多工作区
cd ..
go work init common
继续往工作区里面添加工作区项目
go work use myproject_1
结束
go work sync
go run myproject_1/main.go