GET

url: http://127.0.0.1:8080/users?id=1&name=卷毛狒狒

package main

import (
"github.com/gin-gonic/gin"
"strconv"
)

func main() {
router := gin.Default()
router.GET("/users", func(c *gin.Context) {
idStr := c.Query("id")
id, _ := strconv.Atoi(idStr)
name := c.Query("name")
ageStr := c.DefaultQuery("age", "10")
address, ok := c.GetQuery("address")
if !ok {
address = "gohome"
}
age, _ := strconv.Atoi(ageStr)
c.JSON(200, gin.H{
"id" : id,
"name" : name,
"age" : age,
"address" : address,
})
})
router.Run(":8080")
}
//{"address":"gohome","age":10,"id":1,"name":"juanmaofeifei"}

url: http://127.0.0.1:8080/users?id=1&id=2&id=3

package main

import (
"github.com/gin-gonic/gin"
) func main() {
router := gin.Default()
router.GET("/users", func(c *gin.Context) {
idSli := c.QueryArray("id")
c.JSON(200, gin.H{
"ids" : idSli,
})
})
router.Run(":8080")
} //{"ids":["1","2","3"]}

url: http://127.0.0.1:8080/users?user[id]=1&user[name]=卷毛狒狒&user[age]=10

package main

import (
"github.com/gin-gonic/gin"
) func main() {
router := gin.Default()
router.GET("/users", func(c *gin.Context) {
user := c.QueryMap("user")
c.JSON(200, gin.H{
"user" : user,
})
})
router.Run(":8080")
} //{"user":{"age":"10","id":"1","name":"卷毛狒狒"}}

  

最新文章

  1. OpenCascade Primitives BRep-Cone
  2. DECLARE_GLOBAL_DATA_PTR宏定义问题
  3. [c++] Basic ideas and Style Guide
  4. linux 系统下开机自动启动oracle 监听和实例 (亲测有效)
  5. MySQL的分页
  6. PHP Array 函数
  7. 第二百九十三天 how can I 坚持
  8. maven和libgdx
  9. 【Excel】Excel筛选迟点时间的公式
  10. 用简单的C语言实现多任务轮流切换(模拟操作系统线程机制)
  11. centos系统安装rar解压工具unar
  12. [python]socket.listen(backlog)中的backlog含义
  13. mysql中关于关联索引的问题——对a,b,c三个字段建立联合索引,那么查询时使用其中的2个作为查询条件,是否还会走索引?
  14. [转]window7下利用DockerToolbox安装Docker
  15. SAP PA认证
  16. The Mathematics of the Rubik’s Cube
  17. python学习day9 字符编码和文件处理
  18. 微信小程序与手机APP区别
  19. C++栈学习——顺序栈和链栈的差别
  20. ACM STEPS——Chapter Two——Section One

热门文章

  1. 发现Compound的第二个严重漏洞
  2. VMware安装win7后,安装VMware Tools时报错安装程序无法继续。本程序需要您将此虚拟机上安装的操作系统更新到SP1
  3. 53端口反弹shell
  4. djinn
  5. 【Python 第0课】Why Python?
  6. Ajax是什么?包含什么技术?有什么作用?
  7. vue Cannot read property ‘tapPromise‘ of undefined
  8. rbac-基于角色的权限控制系统(8种常用场景再现)
  9. 4.3 ROS工作空间覆盖
  10. linux安装mongodb磁盘空间不足