August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this subsection, you will see how to use two different major versions of the same Go module in a single Go program. The same technique can be used if you want to use more than two major versions of a Go module at the same time.
The name of the Go source file will be useTwo.go and it is as follows:
package main
import (
v1 "github.com/mactsouk/myModule"
v2 "github.com/mactsouk/myModule/v2"
)
func main() {
v1.Version()
v2.Version()
}
So, you just need to explicitly import the major versions of the Go module you want to use and give them different aliases.
Executing useTwo.go will generate the following kind of output:
$ export GO111MODULE=on $ go run useTwo.go go: creating new go.mod: module ...
Read now
Unlock full access