golang中引用自己github公开的包失败:connected host has failed to respond

本文介绍在Golang编程中如何成功引用并使用自己上传到GitHub上的包。当使用gomod方式下载这些包遇到连接超时问题时,可以通过设置国内代理解决。具体操作包括修改环境变量 GOPROXY 和 GOPRIVATE。

golang编程中,想使用自己上传到github的包

使用go mod方式,下载引用自己上传的包失败:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

更改国内代理即可

go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOPRIVATE=*.corp.example.com

After restarting ComfyUI, please refresh the browser. translate\translate.go:25:2: github.com/abadojack/whatlanggo@v1.0.1: Get "https://proxy.golang.org/github.com/abadojack/whatlanggo/@v/v1.0.1.zip": dial tcp 142.251.33.81:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. translate\translate.go:28:2: github.com/andybalholm/brotli@v1.1.0: Get "https://proxy.golang.org/github.com/andybalholm/brotli/@v/v1.1.0.zip": dial tcp 142.251.33.81:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. translate\translate.go:26:2: github.com/imroc/req/v3@v3.48.0: Get "https://proxy.golang.org/github.com/imroc/req/v3/@v/v3.48.0.zip": dial tcp 142.251.33.81:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. translate\translate.go:29:2: github.com/tidwall/gjson@v1.14.3: Get "https://proxy.golang.org/github.com/tidwall/gjson/@v/v1.14.3.zip": dial tcp 142.251.33.81:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. service\service.go:23:2: github.com/gin-contrib/cors@v1.6.0: Get "https://proxy.golang.org/github.com/gin-contrib/cors/@v/v1.6.0.zip": dial tcp 142.251.33.81:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. service\service.go:24:2: github.com/gin-gonic/gin@v1.9.1: Get "https://proxy.golang.org/github.com/gin-gonic/gin/@v/v1.9.1.zip": dial tcp 142.251.33.81:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. [ComfyUI-Manager] Failed to perform initial fetching 'custom-node-list.json': Traceback (most recent call last): File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\streams.py", line 347, in _wait await waiter asyncio.exceptions.CancelledError The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\ComfyUI\custom_nodes\comfyui-manager\glob\manager_server.py", line 1729, in get_cache json_obj = await manager_util.get_data(uri, True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\ComfyUI\custom_nodes\comfyui-manager\glob\manager_util.py", line 146, in get_data json_text = await resp.text() ^^^^^^^^^^^^^^^^^ File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\client_reqrep.py", line 1260, in text await self.read() File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\client_reqrep.py", line 1218, in read self._body = await self.content.read() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\streams.py", line 418, in read block = await self.readany() ^^^^^^^^^^^^^^^^^^^^ File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\streams.py", line 440, in readany await self._wait("readany") File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\streams.py", line 346, in _wait with self._timer: File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\helpers.py", line 685, in __exit__ raise asyncio.TimeoutError from exc_val TimeoutError [ComfyUI-Manager] Failed to perform initial fetching 'extension-node-map.json': Traceback (most recent call last): File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\streams.py", line 347, in _wait await waiter asyncio.exceptions.CancelledError The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\ComfyUI\custom_nodes\comfyui-manager\glob\manager_server.py", line 1729, in get_cache json_obj = await manager_util.get_data(uri, True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\ComfyUI\custom_nodes\comfyui-manager\glob\manager_util.py", line 146, in get_data json_text = await resp.text() ^^^^^^^^^^^^^^^^^ File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\client_reqrep.py", line 1260, in text await self.read() File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\client_reqrep.py", line 1218, in read self._body = await self.content.read() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\streams.py", line 418, in read block = await self.readany() ^^^^^^^^^^^^^^^^^^^^ File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\streams.py", line 440, in readany await self._wait("readany") File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\streams.py", line 346, in _wait with self._timer: File "C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\python\Lib\site-packages\aiohttp\helpers.py", line 685, in __exit__ raise asyncio.TimeoutError from exc_val TimeoutError FETCH ComfyRegistry Data: 5/85 FETCH ComfyRegistry Data: 10/85 FETCH ComfyRegistry Data: 15/85 FETCH ComfyRegistry Data: 20/85 FETCH ComfyRegistry Data: 25/85 FETCH ComfyRegistry Data: 30/85 FETCH ComfyRegistry Data: 35/85 FETCH ComfyRegistry Data: 40/85 FETCH ComfyRegistry Data: 45/85 FETCH ComfyRegistry Data: 50/85 FETCH ComfyRegistry Data: 55/85 FETCH ComfyRegistry Data: 60/85 FETCH ComfyRegistry Data: 65/85 FETCH ComfyRegistry Data: 70/85 FETCH ComfyRegistry Data: 75/85 FETCH ComfyRegistry Data: 80/85 FETCH ComfyRegistry Data: 85/85 FETCH ComfyRegistry Data [DONE] [ComfyUI-Manager] default cache updated: https://api.comfy.org/nodes FETCH DATA from: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json[ComfyUI-Manager] Due to a network error, switching to local mode. => custom-node-list.json => FETCH DATA from: C:\Documents\Ai\ComfyUI-aki\ComfyUI-aki-v1.6\ComfyUI\custom_nodes\comfyui-manager\custom-node-list.json [DONE] [ComfyUI-Manager] All startup tasks have been completed. [Crystools ERROR] For some reason, pynvml is not working in a laptop with only battery, try to connect and turn on the monitor [Crystools ERROR] Monitor of GPU is turning off (not on UI!) [BizyAir] Fail to get notification unread counts: Cannot connect to host api.bizyair.cn:443 ssl:default [getaddrinfo failed] 我在comfyUI中安装nunchaku有些问题 这个应该怎么修复呢
05-14
### 解决 gopls 模块更新时的网络连接问题 在使用 Go 语言开发时,`gopls` 是官方推荐的语言服务器协议(LSP)实现,用于提供代码补全、跳转等功能。当 `gopls` 模块更新时遇到网络连接问题,通常是因为模块下载依赖于 `proxy.golang.org` 或其他镜像站点,而这些站点可能因网络限制无法正常访问[^1]。 以下是解决该问题的具体方法: #### 方法一:配置 GOPROXY 使用国内镜像 Go 官方提供了模块代理机制,可以通过设置环境变量 `GOPROXY` 来指定模块下载的代理地址。国内有许多可用的 Go 模块镜像站点,例如阿里云和清华大学开源软件镜像站。 ```bash export GOPROXY=https://goproxy.cn,direct ``` 上述命令将 `GOPROXY` 设置为 `https://goproxy.cn`,并在代理不可用时直接连接上游源码库[^2]。如果需要永久生效,可以将该命令添加到 `.bashrc` 或 `.zshrc` 文件中。 #### 方法二:离线模式 如果网络问题持续存在,可以尝试使用离线模式进行模块管理。离线模式下,Go 工具链仅从本地缓存中获取模块,而不尝试连接外部网络。 ```bash export GOOFFLINE=1 ``` 此方法适用于已经下载过所需模块的情况。若某些模块尚未缓存,则仍需通过网络下载[^3]。 #### 方法三:手动下载缺失模块 对于特定模块无法通过代理或直接连接下载的情况,可以手动下载并放置到本地模块缓存目录中。例如,针对 `gopls` 的相关依赖: 1. 找到具体的模块路径(如 `golang.org/x/tools/gopls`)。 2. 在本地克隆仓库或下载压缩。 3. 将文件解压至 `$GOPATH/pkg/mod` 或 `$GOCACHE` 目录下的对应位置。 #### 方法四:调整模块版本 有时,特定版本的模块可能由于网络原因无法下载。可以通过修改 `go.mod` 文件中的版本号来切换到其他可用版本。例如: ```go require golang.org/x/tools v0.1.4 ``` 运行以下命令以同步更改: ```bash go mod tidy ``` 这将重新计算依赖关系并尝试下载新的模块版本[^4]。 ```python # 示例 Python 脚本用于检查模块状态 import subprocess def check_module_status(module_name): result = subprocess.run(["go", "list", "-m", module_name], capture_output=True, text=True) return result.stdout.strip() print(check_module_status("golang.org/x/tools")) ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值