Hugo Module 代理

本页内容

众所周知 Go Module 服务器被墙了,因此需要指定代理服务器或者全局 VPN,而代理服务器比较简单方便,如:GOPROXYCNGOPROXYIO。 而笔者之前很长一段时间利用 Hugo Module 来安装和更新主题,速度十分缓慢,而且经常失败,即使我设置了 GO_PROXY 环境变量。

错误日志

 1hugo: downloading modules …
 2go: github.com/razonyang/hugo-theme-bootstrap@v1.0.0-alpha.1.0.20220708160018-560a68166b0a: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/razonyang/Projects/razonyang/hugo-theme-bootstrap-site/vendor/modules/filecache/modules/pkg/mod/cache/vcs/348a35abd6584f23aeb4a9124871cf51b665ede955a2f430e06713f21b056184: exit status 128:
 3        fatal: the remote end hung up unexpectedly
 4        fatal: early EOF
 5        fatal: index-pack failed
 6hugo: collected modules in 1140149 ms
 7WARN 2022/07/09 16:43:05 failed to download modules: failed to execute 'go [mod download]': failed to execute binary "go" with args [mod download]: go: github.com/razonyang/hugo-theme-bootstrap@v1.0.0-alpha.1.0.20220708160018-560a68166b0a: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/razonyang/Projects/razonyang/hugo-theme-bootstrap-site/vendor/modules/filecache/modules/pkg/mod/cache/vcs/348a35abd6584f23aeb4a9124871cf51b665ede955a2f430e06713f21b056184: exit status 128:
 8        fatal: the remote end hung up unexpectedly
 9        fatal: early EOF
10        fatal: index-pack failed
11 *errors.errorString
12go: github.com/razonyang/hugo-theme-bootstrap@v1.0.0-alpha.1.0.20220708160018-560a68166b0a: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/razonyang/Projects/razonyang/hugo-theme-bootstrap-site/vendor/modules/filecache/modules/pkg/mod/cache/vcs/348a35abd6584f23aeb4a9124871cf51b665ede955a2f430e06713f21b056184: exit status 128:
13        fatal: unable to access 'https://github.com/razonyang/hugo-theme-bootstrap/': GnuTLS recv error (-110): The TLS connection was non-properly terminated.
14Error: failed to get ["-d" "github.com/razonyang/hugo-theme-bootstrap@master"]: failed to execute 'go [get -d github.com/razonyang/hugo-theme-bootstrap@master]': failed to execute binary "go" with args [get -d github.com/razonyang/hugo-theme-bootstrap@master]: go: github.com/razonyang/hugo-theme-bootstrap@v1.0.0-alpha.1.0.20220708160018-560a68166b0a: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/razonyang/Projects/razonyang/hugo-theme-bootstrap-site/vendor/modules/filecache/modules/pkg/mod/cache/vcs/348a35abd6584f23aeb4a9124871cf51b665ede955a2f430e06713f21b056184: exit status 128:
15        fatal: unable to access 'https://github.com/razonyang/hugo-theme-bootstrap/': GnuTLS recv error (-110): The TLS connection was non-properly terminated.
16 *errors.errorString

解决方法

后来搜索了下才知道,Hugo 遵循 HUGO_MODULE_PROXY 环境变量,而非 GOPROXY,除此之外还可以在配置文件中指定代理服务器:

config.toml

1[module]
2  proxy = 'https://goproxy.cn'

config.yaml

1module:
2  proxy: https://goproxy.cn

config.json

1{
2   "module": {
3      "proxy": "https://goproxy.cn"
4   }
5}

至于之前为什么更新时而成功时而失败,也许是因为开了全局 VPN。

razonyang
2024年11月24日星期日 2022年7月30日星期六