1.下载Gin:

 go get -u github.com/gin-gonic/gin

出现:

package github.com/gin-gonic/gin: no Go files in E:\GO1\src\github.com\gin-gonic\gin

解决办法

在cmd中运行:

  go env -w GO111MODULE=on

   go env -w GOPROXY=https://goproxy.io,direct

设置后,重新运行: go get -u github.com/gin-gonic/gin

2.运行项目

在C:\Users\Administrator\go\ 下创建 src/gin/ 文件夹,创建main.go 文件,添加文档说的代码:

package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	r := gin.Default()
	r.GET("/", func(c *gin.Context) {
		c.String(http.StatusOK, "搭建完成,辛苦了")
	})
	r.Run(":8888") // 端口号8888

}

运行命令: go run .\main.go

出现:

main.go:3:8: cannot find module providing package github.com/gin-gonic/gin: working directory is not part of a module

解决办法:

  go mod init gin

  go mod edit -require github.com/gin-gonic/gin@latest