File tree Expand file tree Collapse file tree 2 files changed +96
-0
lines changed
Expand file tree Collapse file tree 2 files changed +96
-0
lines changed Original file line number Diff line number Diff line change 22
33## 目录
44
5+ ### Go
6+
7+ [ 设置代理加速国内源] ( go/go-proxy-qiniu.md )
8+
59### Python
610
711[ 打包并发布包到 PyPI] ( python/build-and-publish-package-to-pypi.md )
12+
Original file line number Diff line number Diff line change 1+ # 设置代理加速国内源
2+
3+ ## Go 1.13 及以上(推荐)
4+
5+ 打开你的终端并执行
6+
7+ ``` bash
8+ go env -w GO111MODULE=on
9+ go env -w GOPROXY=https://goproxy.cn,direct
10+ ```
11+
12+ 完成。
13+
14+ ## macOS 或 Linux
15+
16+ 打开你的终端并执行
17+
18+ ``` bash
19+ export GO111MODULE=on
20+ export GOPROXY=https://goproxy.cn
21+ ```
22+
23+ 或者
24+
25+ ``` bash
26+ echo " export GO111MODULE=on" >> ~ /.profile
27+ echo " export GOPROXY=https://goproxy.cn" >> ~ /.profile
28+ source ~ /.profile
29+ ```
30+
31+ 完成。
32+
33+ ## Windows
34+
35+ 打开你的 PowerShell 并执行
36+
37+ ``` powershell
38+ C:\> $env:GO111MODULE = "on"
39+ C:\> $env:GOPROXY = "https://goproxy.cn"
40+ ```
41+
42+ 或者
43+
44+ 1 . 打开“开始”并搜索“env”
45+ 2 . 选择“编辑系统环境变量”
46+ 3 . 点击“环境变量…”按钮
47+ 4 . 在“<你的用户名> 的用户变量”章节下(上半部分)
48+ 5 . 点击“新建…”按钮
49+ 6 . 选择“变量名”输入框并输入“GO111MODULE”
50+ 7 . 选择“变量值”输入框并输入“on”
51+ 8 . 点击“确定”按钮
52+ 9 . 点击“新建…”按钮
53+ 10 . 选择“变量名”输入框并输入“GOPROXY”
54+ 11 . 选择“变量值”输入框并输入“https://goproxy.cn”
55+ 12 . 点击“确定”按钮
56+
57+ 完成。
58+
59+ ## 自托管 Go 模块代理
60+ 你的代码永远只属于你自己,因此我们向你提供目前世界上最炫酷的自托管 Go 模块代理搭建方案。通过使用 Goproxy 这个极简主义项目,你可以在现有的任意 Web 服务中轻松地引入 Go 模块代理支持,要知道 Goproxy.cn 就是基于它搭建的。
61+
62+ 创建一个名为 goproxy.go 的文件
63+ ``` golang
64+ package main
65+
66+ import (
67+ " net/http"
68+ " os"
69+
70+ " github.com/goproxy/goproxy"
71+ )
72+
73+ func main () {
74+ http.ListenAndServe (" localhost:8080" , &goproxy.Goproxy {
75+ GoBinEnv: append (
76+ os.Environ (),
77+ " GOPROXY=https://goproxy.cn,direct" , // 使用 Goproxy.cn 作为上游代理
78+ " GOPRIVATE=git.example.com" , // 解决私有模块的拉取问题(比如可以配置成公司内部的代码源)
79+ ),
80+ ProxiedSUMDBs: []string {
81+ " sum.golang.org https://goproxy.cn/sumdb/sum.golang.org" , // 代理默认的校验和数据库
82+ },
83+ })
84+ }
85+ ```
86+ 并且运行它
87+
88+ $ go run goproxy.go
89+ 然后通过把 GOPROXY 设置为 http://localhost:8080 来试用它。另外,我们也建议你把 GO111MODULE 设置为 on。
90+
91+ 就这么简单,一个功能完备的 Go 模块代理就搭建成功了。事实上,你还可以将 [ Goproxy] ( https://github.com/goproxy/goproxy ) 结合着你钟爱的 Web 框架一起使用,比如 [ Gin] ( https://pkg.go.dev/github.com/gin-gonic/gin#WrapH ) 和 [ Echo] ( https://pkg.go.dev/github.com/labstack/echo/v4#WrapHandler ) ,你所需要做的只是多添加一条路由而已。更高级的用法请查看[ 文档] ( https://pkg.go.dev/github.com/goproxy/goproxy ) 。
You can’t perform that action at this time.
0 commit comments