Background
When we add a new feature to gwdemo3...
package gwdemo3
import "fmt"
func Hello(s string) string {
return fmt.Sprintf("Hello, %s!", s)
}
func Bye(s string) string {
return fmt.Sprintf("Bye, %s!", s)
}
Slide 10
Slide 10 text
Background
And want to use it on gwdemo1 and gwdemo2 locally...
package main
import (
"fmt"
"github.com/110y/gwdemo3"
)
func main() {
fmt.Println(gwdemo3.Hello("Workspace"))
fmt.Println(gwdemo3.Bye("Workspace"))
}
Slide 11
Slide 11 text
Background
We have to add a replace directive to the go.mod
fi
le
module github.com/110y/gwdemo1
go 1.18
require github.com/110y/gwdemo3 v0.0.0-20220218011518-502c64a9beed
replace github.com/110y/gwdemo3 => ../gwdemo3
Slide 12
Slide 12 text
Background
Problem
ɾHave to add replace directive to each module's go.mod
fi
le.
ɾHave to remove replace directive before submitting the code.
Slide 13
Slide 13 text
Background
But working with the replace directive can
often be awkward: each module
developer might have working versions at
di
ff
erent location on disk, so having the
directive in a
fi
le that needs to be
distributed with the module isn't a good
fi
t for all use cases.
https://go.googlesource.com/proposal/+/master/design/45713-workspace.md
Proposal: Multi-Module Workspaces in cmd/go
Workspace Mode
$ cd gwdemo1
$ go env GOWORK
/path/to/gwdemo-workspace/go.work
Workspace
Slide 22
Slide 22 text
Workspace Mode
$ go help work
...
To determine whether the go command is operating
in workspace mode, use the "go env GOWORK"
command. This will specify the workspace file
being used.
...
Workspace
Workspace Mode
$ cd gwdemo1
$ go env GOWORK
/path/to/gwdemo-workspace/go.work
$ go run .
Hello, Workspace!
Bye, Workspace!
Workspace
Slide 26
Slide 26 text
Problem
✅ Have to add replace directive to each module's go.mod
fi
le.
✅ Have to remove replace directive before submitting the code.
Workspace Mode
Slide 27
Slide 27 text
Workspace Mode
$ cd gwdemo1
$ go env GOWORK
/path/to/gwdemo-workspace/go.work
$ GOWORK=off go run .
# github.com/110y/gwdemo1
./main.go:12:22: undefined: gwdemo3.Bye
Check the actual behavior with GOWORK=o
f
Slide 28
Slide 28 text
Workspace Mode
-work
fi
le
fl
ag...?
https://go-review.googlesource.com/c/go/+/385995/
Slide 29
Slide 29 text
Agenda
ɾBackground
ɾWorkspace Mode
ɾUse cases
Slide 30
Slide 30 text
Use cases
Microservice Chassis Pattern
https://microservices.io/patterns/microservice-chassis.html