Go Workspaces
Workspaces
Go 1.18 introduced workspace support. A workspace lets you manage multiple modules together.
-
Create a workspace.
$ mkdir workspace $ cd workspace $ go work init -
Create the
myappmodule.$ mkdir myapp $ cd myapp $ go mod init example.com/myapp -
Add the
myappmodule to the workspace.$ cd .. $ go work use ./myappmyapp.go
package main import "fmt" import "example.com/mypkg" func main() { fmt.Println(mypkg.Hello()) } -
Create the
mypkgmodule.$ mkdir mypkg $ cd mypkg $ go mod init example.com/mypkg -
Add the
mypkgmodule to the workspace.$ cd .. $ go work use ./mypkgmypkg.go
package mypkg func Hello() string { return "Hello world!" } -
Run the program.
$ go run example.com/myapp Hello world!