go模块的全局代理。见:https://goproxy.io
Requirements
It invokes the local go command to answer requests.
The default cacheDir is GOPATH, you can set it up by yourself according to the situation.
Build
git clone https://github.com/goproxyio/goproxy.git
cd goproxy
make
Started
Proxy mode
./bin/goproxy -listen=0.0.0.0:80 -cacheDir=/tmp/test
If you run `go get -v pkg` in the proxy machine, should set a new GOPATH which is different from the old GOPATH, or mayebe deadlock.
See the file test/get_test.sh.
Router mode
使用-proxy标志开关到“路由器模式”,它实现路由过滤器到路由私有模块或公共模块。
direct
+----------------------------------> private repo
|
match|pattern
|
+---+---+ +----------+
go get +-------> |goproxy| +-------> |goproxy.io| +---> golang.org/x/net
+-------+ +----------+
router mode proxy mode
在路由器模式下,使用-exclude标志集模式,直接指向与模块路径匹配的repo,模式匹配的是指定的完整路径,而不仅仅是主机组件。
./bin/goproxy -listen=0.0.0.0:80 -cacheDir=/tmp/test -proxy https://goproxy.io -exclude "*.corp.example.com,rsc.io/private"
使用docker图像
docker run -d -p80:8081 goproxy/goproxy
使用-v标志保存代理模块数据(将cacheDir更改为您自己的目录):
docker run -d -p80:8081 -v cacheDir:/go goproxy/goproxy
Docker Compose
docker-compose up
Appendix
export GOPROXY=http://localhostexport GOPROXY=direct