D:workgoPath
go get -u github.com/gin-gonic/gin
报错:go get: module github.com/gin-gonic/gin: Get "https://proxy.golang.org/github.com/gin-gonic/gin/@v/list": dial tcp 216.58.200.241: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.开启gomodule
go env -w GO111MODULE=on
设置goproxygo env -w GOPROXY=https://goproxy.cn
go env
go get -u github.com/gin-gonic/gin
gopath下会多出pkg目录
(我用的编辑器是idea加上go的插件)
因为开启gomodule支持,项目不能在gopath下,
不然会报错:
$GOPATH/go.mod exists but should not
D:workgoWorkspacesrchelloGin
(复制粘贴过去,不管错误提示直接运行)
package main
import "github.com/gin-gonic/gin"
func main() {
engine := gin.Default()
engine.GET("/", func(context *gin.Context) {
context.String(200, "hello, gin")
})
engine.Run()
}
报错:
no required module provides package github.com/gin-gonic/gin;配置项目gopath
D:workgoWorkspace
GOPROXY=https://goproxy.cn
(否则编辑器提示不可用)
cmd
go mod init helloGin
go mod edit -require github.com/gin-gonic/gin@latest
go mod tidy
(go mod init "helloGin"与项目保持一致)
否则可能还会出现以下错误:
go: github.com/gin-gonic/gin@v1.7.1: missing go.sum entry;再次运行main.go
然后项目gopath下会多出pkg路径
helloGin下多出go.mod、go.sum
不当之处,请予指正。



