0. 前言 在大陆地区我们无法直接通过 go get
命令获取到一些第三方包,最常见的就是 golang.org/x
下面的各种优秀的包. 解决方案如下:
1 2 3 4 5 6 7 8 9 export GO111MODULE=onexport GOPROXY=https://goproxy.cngo env -w GOPROXY=https://goproxy.cn,direct go env -w GOPRIVATE=*.corp.example.com
本文将重点介绍 go module 的 proxy 配置实现,包括如下两种的代理配置:
1. goproxy https://github.com/goproxyio/goproxy
1.1 安装go 1 2 3 4 wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1.13.4.linux-amd64.tar.gz export PATH=$PATH :/usr/local/go/bin go version
1.2 安装goproxy 1 2 3 git clone https://github.com/goproxyio/goproxy.git cd goproxy/make
1.3 代理 1 2 3 4 5 6 ./bin/goproxy -cacheDir=/tmp/test -listen=0.0.0.0:8082 GOPROXY=http://服务端ip:8082 go get -v github.com/spf13/cobra
1.4 nginx配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ./bin/goproxy -cacheDir=/tmp/test -listen :8082 -proxy https://goproxy.cn -exclude liuvv.com server { server_name goproxy.liuvv.com; listen 80 ; listen 443 ssl http2 ; access_log /var/log/nginx/goproxy_access_log; error_log /var/log/nginx/goproxy_error_log notice ; location / { proxy_set_header X-Real-IP $remote_addr ; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ; proxy_set_header Host $http_host ; proxy_connect_timeout 300s ; proxy_send_timeout 300s ; proxy_read_timeout 300s ; proxy_pass http://127.0.0.1:8082; } }
2. Athens 1 2 3 4 5 git clone https://github.com/gomods/athens cd athens make build-ver VERSION="0.7.0" ./athens -version
1 2 3 export ATHENS_STORAGE_TYPE=disk export ATHENS_DISK_STORAGE_ROOT=~/athens-storage./athens
1 2 3 4 5 6 7 8 9 export GO111MODULE=on export GOPROXY=http:git clone https://github.com/athens-artifacts/walkthrough.git cd walkthroughgo run . curl 服务器ip:3000/github.com/athens-artifacts/samplelib/@v/list
3. 参考资料