range

If there were you, the world would be just right

通过D:\go\src\runtime\internal\sys\zversion.go的文件 设置版本

package sys

const StackGuardMultiplierDefault = 1

const TheVersion = `go1.20.5`(新增)

1、querystring,的是URL中​​?​​​后面携带的参数,例如:​​/user/search?username=小王子&address=沙河​​。 获取请求的querystring参数的方法如下。

username := c.DefaultQuery("username", "小王子")
//username := c.Query("username")
address := c.Query("address")
//输出json结果给调用方
c.JSON(http.StatusOK, gin.H{
  "message":  "ok",
  "username": username,
  "address":  address,
})

2、获取form参数,当前端请求的数据通过form表单提交时,例如向​​/user/search​​发送一个POST请求,获取请求数据的方式如下。c.PostForm

username := c.PostForm("username")
address := c.PostForm("address")
//输出json结果给调用方
c.JSON(http.StatusOK, gin.H{
  "message":  "ok",
  "username": username,
  "address":  address,
})

3、获取json参数,当前端请求的数据通过JSON提交时,例如向​​/json​​发送一个POST请求,则获取请求参数的方式如下。

b, _ := c.GetRawData()  // 从c.Request.Body读取请求数据
// 定义map或结构体
var m map[string]interface{}
// 反序列化
_ = json.Unmarshal(b, &m)

c.JSON(http.StatusOK, m)

阅读剩余部分...


安装gin失败了

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

错误提示:

# cd .; git clone -- https://github.com/gin-gonic/gin E:\goproject\src\github.com\gin-gonic\gin
Cloning into 'E:\goproject\src\github.com\gin-gonic\gin'...
fatal: unable to access 'https://github.com/gin-gonic/gin/': Failed to connect to github.com port 443 after 21015 ms: Couldn't connect to server
package github.com/gin-gonic/gin: exit status 128

解决办法:使用代理。 在命令行里输入以下命令

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