idea 添加 gosdk报错:
The selected directory is not a valid home for Go SDK
解决方法:
C:\Program Files\Go\src\runtime\internal\sys\zversion.go添加内容
const TheVersion = `go1.20.3`

安装gin
1.配置代理

GOPROXY=https://goproxy.cn,direct

2.

D:\golang\study>go env -w GO111MODULE=on

3.go mod init

D:\golang\study>go mod init study
go: creating new go.mod: module study

4.下载依赖
go get -u github.com/gin-gonic/gin

安装中遇到的问题:

报错:warning: GOPATH set to GOROOT (C:\Program Files\Go) has no effect
解决方案:
set GOPATH=C:\Program Files\Go\GOPATH
set GOROOT=C:\Program Files\Go
设置环境变量path C:\Program Files\Go\bin

报错:
D:\golang\study> go get -u github.com/gin-gonic/gin
# cd C:\Users\Administrator\go\src\github.com\gin-gonic; git clone — https://github.com/gin-gonic/gin C:\Users\Administrator\go\src\github.com\gin-gonic\gin
Cloning into ‘C:\Users\Administrator\go\src\github.com\gin-gonic\gin’…
fatal: unable to access ‘https://github.com/gin-gonic/gin/’: Failed to connect to github.com port 443: Timed out
package github.com/gin-gonic/gin: exit status 128
解决方案:
设置代理
D:\golang\study>go env -w GOPROXY=https://goproxy.cn,direct

5.创建main.go文件

package main
 
import (
	"fmt"
	"github.com/gin-gonic/gin"
)
 
func main() {
 
	// 创建一个默认的路由引擎
	r := gin.Default()
 
	// 配置路由
	r.GET("/", func(c *gin.Context) {
		c.JSON(200, gin.H{
			// c.JSON:返回 JSON 格式的数据
			"message": "Hello world!",
		})
	})
 
	fmt.Println("hello")
	// 启动 HTTP 服务,默认在 0.0.0.0:8080 启动服务
	r.Run()
 
}

发表评论

邮箱地址不会被公开。 必填项已用*标注