r/programming • • Sep 27 '26

Don't couple your Go code to GitHub

https://iain.rocks/blog/dont-couple-your-go-code-to-github
491 Upvotes

136 comments sorted by

View all comments

Show parent comment

5

u/Kraigius Sep 28 '26 edited Sep 28 '26

Afaik, in Go you can configure multiple package sources, it's just a bit different.

There's the GOPROXY envvar. Go always download from a proxy owned by google, then fallback to download the source code directly from github (or whichever source that you need).

It's not configurable to specific packages but this is like configuring your global sources.

If your org have their own proxy then you can cache your deps and configure your GOPROXY to prioritize it.

You can use this to have your org scan and vet your deps.

Otherwise, for finer control you can add an instruction inside your go.mod file to fetch your depA from gitlab instead of github, or anywhere else.

module example.com/mymodule

go 1.14

require (
    github.com/orgX/depA v1.2.3
)

replace github.com/orgX/depA => gitlab.com/orgX/depA

In term of design, the syntax for this and the workflow kinda feel like an afterthought.

Golang download source code instead of a compiled artifact, so that's probably the consequence of that choice.