Notice the following:
- The greeting package is called
greeting
in both thev1
andv2
directories. - The greeting package is NOT called
v1
orv2
like how it is in this Kubernetes example. - Note that I have a single
go.mod
file in the root directory, wheremain.go
is. - The first line in the
go.mod
file ismodule github.com/codegold79/simple-versioning-with-go
. That sets the namespace for all the packages in the repo. - I ran
go mod tidy
to bring in dependencies (probably not needed, but good practice). - Run
go run main.go
and see that I can use whatever package I imported usinggreeting
.
Try it out yourself. Change the import path to V2 and see the greeting change. You didn't need to reset all the imported package aliases and update them all in the code.