If you run go get -v pkg in the proxy machine, you should set a new GOPATH which is different from the original GOPATH, or you may encounter a deadlock.
Use the -proxy flag combined with the -exclude flag to enable Router mode, which implements route filter to routing private modules or public modules.
direct
+----------------------------------> private repo
|
match|pattern
|
+---+---+ +----------+
go get +-------> |goproxy| +-------> |goproxy.io| +---> golang.org/x/net
+-------+ +----------+
router mode proxy mode
In Router mode, use the -exclude flag to set a glob pattern. The glob will specify what packages should not try to resolve with the value of -proxy. Modules which match the -exclude pattern will resolve direct to the repo which
matches the module path.
NOTE: Patterns are matched to the full path specified, not only to the host component.
Some private modules are gated behind git authentication. To resolve this, you can force git to rewrite the URL with a personal access token present for auth
GOPROXY
A global proxy for go modules. see: https://goproxy.io
Requirements
This service invokes the local
go
command to answer requests.The default
cacheDir
isGOPATH
, you can set it up by yourself according to the situation.Build
Started
Proxy mode
If you run
go get -v pkg
in the proxy machine, you should set a newGOPATH
which is different from the originalGOPATH
, or you may encounter a deadlock.See
test/get_test.sh
.Router mode
Use the
-proxy
flag combined with the-exclude
flag to enableRouter mode
, which implements route filter to routing private modules or public modules.In
Router mode
, use the-exclude
flag to set a glob pattern. The glob will specify what packages should not try to resolve with the value of-proxy
. Modules which match the-exclude
pattern will resolve direct to the repo which matches the module path.NOTE: Patterns are matched to the full path specified, not only to the host component.
Private module authentication
Some private modules are gated behind
git
authentication. To resolve this, you can force git to rewrite the URL with a personal access token present for authThis can be done for other git providers as well, following the same pattern
Use docker image
Use the -v flag to persisting the proxy module data (change cacheDir to your own dir):
Docker Compose
Kubernetes
Deployment:
Deployment (with gitconfig secret):
Appendix
export GOPROXY=http://localhost[:PORT]
to use your goproxy.export GOPROXY=direct
to directly access modules without your goproxy.Sponsors