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

The selected directory is not a valid home for Go SDK
win10 go 版本 1.17.3 goland 2019.2.3 goland 指定go 版本 报错 The selected directory is not a valid home for Go SDK

修改 D:/Program Files/go1.17.3/src/runtime/internal/sys/zversion.go 添加 const TheVersion = go1.17.3 搞定


ik分词器安装 声明:安装完成后需要重新启动elasticsearch,elasticsearch-head,kibana

1.进入elasticsearch目录

# git文档查看 https://github.com/medcl/elasticsearch-analysis-ik

#执行安装
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.1/elasticsearch-analysis-ik-7.6.1.zip

2.重启es

3.elasticsearch-plugin list 可以通过这个命令来查看加载进来的插件