godependenciesgo-modulesgo-getgo-build

Using a particular version for golang dependency module


I'm trying to build postfix-exporter code from the github link. It has a dependency on the go-systemd package as mentioned in go.mod file github.com/coreos/go-systemd/v22 v22.0.0. I see in the go.mod file , the mentioned version for the package is v22.0.0. But when I run go get -u for this path, it starts downloading the latest version ( v22.2.0) of go-systemd which has an issue in the latest commit and causing failure to compile . The error coming in that is

github.com/coreos/go-systemd/v22@v22.2.0/sdjournal/journal.go:313:60: error: '_SD_ARRAY_STATIC' undeclared here (not in a function) // my_sd_id128_to_string(void *f, sd_id128_t boot_id, char s[_SD_ARRAY_STATIC SD_ID128_STRING_MAX]) ^ In file included from /usr/include/systemd/sd-journal.h:31:0, from pkg/mod/github.com/coreos/go-systemd/v22@v22.2.0/sdjournal/journal.go:27: pkg/mod/github.com/coreos/go-systemd/v22@v22.2.0/sdjournal/journal.go:313:77: error: expected ']' before numeric constant // my_sd_id128_to_string(void *f, sd_id128_t boot_id, char s[_SD_ARRAY_STATIC SD_ID128_STRING_MAX])

I want to know , how to compile for a specific version of any dependency module if this is not the way or I'm missing some option required to honor the version of dependency packages mentioned in go.mod

Thanks very much in advance and please pardon my golang knowledge.


Solution

  • Don't use -u. The purpose of -u is to allow Go to try to upgrade you to the latest minor or patch version:

    The -u flag instructs get to update modules providing dependencies of packages named on the command line to use newer minor or patch releases when available.

    If you're just trying to install dependencies, use go get.