映射查询字符串或表单参数,类似于 PHP 的字符串下标数组参数。代码:

package main

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

func main() {
	router := gin.Default()

	router.POST("/post", func(c *gin.Context) {
		ids := c.QueryMap("ids")
		names := c.PostFormMap("names")

		fmt.Printf("ids: %v, names %v", ids, names)
	})

	router.Run(":8080")
}

用 curl 发送请求:

$ curl 'http://localhost:8080/post?ids[a]=1234&ids[b]=hello' -X POST -d 'names[first]=thinkerou&names[second]=tianou'

服务端控制台输出:

ids: map[a:1234 b:hello], names map[first:thinkerou second:tianou]