In https://golangbyexample.com/packages-modules-go-second/ the author talks about Importing package from different module locally. Basically what is said here is:
Make directory tree like
.
├── math
│ ├── go.mod
│ └── math.go
└── school
├── go.mod
└── school.go
In math directory run go mod init sample.com/math
In school directory run go mod init school
math.go
file should look like
package math
func Add(a, b int) int {
return a + b
}
school.go
file should look like
package main
import (
"fmt"
"sample.com/math"
)
func main() {
fmt.Println(math.Add(2, 4))
}
school/go.mod
file should look like
module school
go 1.13
replace sample.com/math => ../math
In school directory run go run school.go
Now you will see that school/go.mod
is changed to
module school
go 1.13
replace sample.com/math => ../math
require sample.com/math v0.0.0-00010101000000-000000000000 // indirect
The thing that is bothering me is, neither school
nor math
is under any sort of version control (both are in my local machine). So, where is it getting this version number.
- How to set the version number that is showed in
go.mod
file (in this case v0.0.0-00010101000000-000000000000)? - How to import a different version of a package from different module locally?