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月5日 星期二 2022年7月30日 星期六