代码:
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()
}
错误:
C:\Users\hxia\go\Gin>go run main.go
main.go:3:8: no required module provides package github.com/gin-gonic/gin; to add it:
go get github.com/gin-gonic/gin
C:\Users\hxia\go\Gin>go get github.com/gin-gonic/gin
go get: module github.com/gin-gonic/gin: Get "https://goproxy.cn/github.com/gin-gonic/gin/@v/list": dial tcp 163.181.42.206: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.
环境:
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\hxia\AppData\Local\go-build
set GOENV=C:\Users\hxia\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\hxia\go\pkg\mod
set GONOPROXY=.gitlab.com,.gitee.com
set GONOSUMDB=.gitlab.com,.gitee.com
set GOOS=windows
set GOPATH=C:\Users\hxia\go
set GOPRIVATE=.gitlab.com,.gitee.com
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Users\hxia\@hxia\GoLang
set GOSUMDB=sum.golang.google.cn
set GOTMPDIR=
set GOTOOLDIR=C:\Users\hxia\@hxia\GoLang\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.2
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\hxia\go\Gin\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\hxia\AppData\Local\Temp\go-build2669851048=/tmp/go-build -gno-record-gcc-switches
描述:
随着 go get 下载 Gin 模块,它显示失败并出现连接错误,检查它似乎配置正确的环境:
set GO111MODULE=on
set GOPROXY=https://goproxy.cn,direct
将 GOPROXY 更改为https://goproxy.io.direct它也失败了。
我在visual studio中配置了一个http_proxy,然后挂起代理是否有问题,所以去掉代理,把代理从HTTP改成HTTPS,都失败了。
有没有高手可以指出这个问题,我该如何解决这个问题?非常感谢!!