You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境下执行go get github.com/gin-gonic/gin连接失败问题求助

Fixing Go Get Connection Failures When Downloading Gin Module

Hey there, let's work through this Go module download issue together. From the error logs and environment config you shared, the core problem is that go get can't establish a connection to the GOPROXY servers you've tried (goproxy.cn and goproxy.io), which is blocking you from pulling the Gin module. Let's break down the possible causes and solutions step by step:

Problem Breakdown

The error message indicates a TCP connection timeout to the proxy server, which points to a few potential issues:

  • Residual system-level proxy settings left over from your Visual Studio configuration
  • Network restrictions (like firewalls or corporate network policies) blocking HTTPS requests to proxy servers
  • Conflicts in your GOPROXY-related environment variables

Step-by-Step Solutions

1. Fully Clear System Proxy Settings

Even if you removed proxy config from Visual Studio, system-level environment variables might still be interfering with Go's network requests:

  • For Command Prompt (CMD):
    set http_proxy=
    set https_proxy=
    set all_proxy=
    
  • For PowerShell:
    $env:http_proxy = $null
    $env:https_proxy = $null
    $env:all_proxy = $null
    

After running these commands, open a brand new terminal window and try go get github.com/gin-gonic/gin again.

2. Temporarily Bypass the Proxy

If your network can access GitHub directly, skip the proxy entirely by setting GOPROXY to direct:

set GOPROXY=direct
go get github.com/gin-gonic/gin

Note: This only works if your network allows direct connections to GitHub. If you're behind a strict corporate firewall, this might not help.

3. Check Firewall & Security Software

Firewalls or antivirus tools often block outgoing HTTPS requests from command-line tools like go. Try temporarily disabling your firewall/antivirus, then run the go get command again to see if that resolves the timeout.

4. Manually Install the Gin Module

If all proxy-based methods fail, you can manually add the Gin module to your Go module cache:

  1. Head to the Gin GitHub repo, download the latest source code as a ZIP file.
  2. Extract the ZIP, then move the folder to C:\Users\hxia\go\pkg\mod\github.com\gin-gonic\gin@v<VERSION> (replace <VERSION> with the latest release number, like v1.9.1).
  3. Run go mod tidy in your project directory to let Go recognize the manually installed module.

5. Upgrade Your Go Version

You're using Go 1.16.2, which is a bit outdated. Newer Go versions (1.21+) have better module download logic and network error handling. Upgrading to a stable recent version might resolve underlying compatibility issues.

Verify the Fix

Once you've tried one of the solutions, run your Gin code again:

package main
import "github.com/gin-gonic/gin"
func main() {
    r := gin.Default()
    r.Handle("GET", "/ping", func(context *gin.Context) {
        context.JSON(200, gin.H{
            "message": "pong",
        })
    })
    r.Run()
}

If there are no import errors, visit http://localhost:8080/ping in your browser—you should get a {"message":"pong"} response, confirming everything works.

内容的提问来源于stack exchange,提问作者lubanseven

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 09:27:31