D:\work\goPath
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.
go env -w GO111MODULE=on
go 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:\work\goWorkspace\src\helloGin
(复制粘贴过去,不管错误提示直接运行)
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;
D:\work\goWorkspace
GOPROXY=https://goproxy.cn
(否则编辑器提示不可用)
cmd
go mod init gin
go mod edit -require github.com/gin-gonic/gin@latest
go mod tidy
否则可能还会出现以下错误:
go: github.com/gin-gonic/gin@v1.7.1: missing go.sum entry;
然后项目gopath下会多出pkg路径
helloGin下多出go.mod、go.sum
不当之处,请予指正。