I have a package hello
which contains the files go.mod
and hello.go
and a package say_things
with files go.mod
and say_things.go
.
hello.go
:
package main
import "github.com/user/say_things"
func main() {
say_things.SayBye()
}
say_things.go
:
package say_things
import "fmt"
func SayBye() {
fmt.Println("BYE")
}
Both these projects are github projects. When I run hello.go
, it prints "BYE" as expected. I now update SayBye
to be:
package say_things
import "fmt"
func SayBye() {
fmt.Println("GO AWAY")
}
and push the changes to github. I again run hello.go
, expecting it to say "GO AWAY", but it doesn't. It still says BYE
. I remove the go.sum
generated and go run hello.go
again, but still it says BYE
. I then go to go/pkg/mod/github.com/user/
and delete say_bye@v0.0.0-<hash>
, and run hello.go
again. Still, nothing changes. Next, I run go get github.com/user/say_things
, still I get BYE
.
How do I get hello.go
to run the updated say_hello
code?
A way to update your code by doing the following change.
Open your go.mod
file in your hello
project and replace
the current version
written against github.com/user/say_things
with the last commit hash of your say_things
project.
In other words, in go.mod
file
Replace github.com/user/say_things <current-version>
with github.com/user/say_things <last-commit-hash>
And finally run:
$ go mod tidy
$ go mod vendor