Today on a bright day, Sunday Funday, but ruined by something that made me furious for an hour. Actually, I’ve stuck with this issue since last night (Saturday Night), but since I’m really tired, I decide to stop and rest and continue again on Sunday.
I have a high expectation on this Mabar, it should be a platform, that available on many interfaces (Mobile, Desktop, Web). For the tech-stack, I use Golang as the backend, Kubernetes as the infrastructure, and Digital Ocean behind them as the Server.
So the issues is, I have a private module (Golang module), a simple library that will be imported by my backend API. But somehow, I can’t get the module and always bring errors when I do the
go get command.
Let’s say the package name is
lucifer. And it always throw error on the terminal. That really made me mad on it.
$ go get -v bitbucket.org/compay/lucifer
go: finding bitbucket.org/compay/lucifer latest
go: downloading bitbucket.org/compay/lucifer v0.0.0-20190921175342-61a76c096369
verifying email@example.com: firstname.lastname@example.org: reading https://email@example.com: 410 Gone
If you look the message, it says the package is gone or not available in sum.golang.org.
At first, I think this happens because I forgot to enforce SSH on bitbucket, as I ever write it here: https://medium.com/easyread/today-i-learned-fix-go-get-private-repository-return-error-terminal-prompts-disabled-8c5549d89045
But, it still not worked well. It still keeps returning an error when I do the
go get commands, even I force it only using SSH.
So, after searching for this issue on the internet, I found the root-causes. This only happens on Golang from version 1.13. I can verify this after reading this release https://golang.org/doc/go1.13#modules
So, this happened because there’s a new feature about proxy in this Golang version.
Actually there are a few solutions that we can choose.
- Using GOPRIVATE
As stated in the release doc of Go 1.13,
The new GOPRIVATE environment variable indicates module paths that are not publicly available. It serves as the default value for the lower-level GONOPROXY and GONOSUMDB variables, which provide finer-grained control over which modules are fetched via proxy and verified using the checksum database.
Means, to solve the issue above, we can just fill the
GOPRIVATE variable in our system. Add this command in the
~/.bashrc. *Change the export value based on your company/org name.
And to verify if this worked, you can do the
go env command. It’s should be more like this.
$ go env
And now I can do the
go get command for my private repository.
$ go get bitbucket.org/company/lucifer
go: finding bitbucket.org/company/lucifer latest
go: downloading bitbucket.org/company/lucifer v0.0.0-20190921175342-61a76c096369
go: extracting bitbucket.org/company/lucifer v0.0.0-20190921175342-61a76c096369
env-variable will tell the
go get command to use the private host proxy to retrieve the package.
- Using GONOSUMDB
Another solution, maybe using the
GONOSUMDB variable. I still don’t try this, but it seems works after reading this proposal https://go.googlesource.com/proposal/+/master/design/25530-sumdb.md
So you can set this in your environment variable:
Actually this issue only happens in new Golang version 1.13 and afterward. So before updating your Golang version, make sure to set this environment variable.
Here a few links that may be related to this issue, thanks to noveaustack for finding this and posting this in Stackoverflow, I just reposted this because I just know this issue and as a new thing I learned.
- Stackoverflow answer: https://stackoverflow.com/a/57887036/4075313
- Proposal about Go Sum DB for go module: https://go.googlesource.com/proposal/+/master/design/25530-sumdb.md
- Proxying Checksum DB: https://docs.gomods.io/configuration/sumdb/
- Github Issues related to this issue: #33985 and #32291