Open hyzgh opened 3 years ago
It seems that it will be supported in v1.7 https://github.com/gin-gonic/gin/pull/2484
@Doarakko Thank you for pointing that out. I update my gin dependency to the latest, but it still doesn't work. I think what that MR solves is to bind a map, as I need to bind a struct with a map embedded. It's different.
@hyzgh Thank you and sorry for the misunderstanding.
mark: this feature is still not suppoted by gin.
Somehow, the *gin.Context provides a method called QueryMap
, you can use it to do your own mapping.
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
type Req struct {
Ext map[string]string `form:"ext"`
}
func main() {
r := gin.Default()
r.GET("/map", func(c *gin.Context) {
ext := c.QueryMap("ext")
fmt.Println(ext)
// output: map[foo:bar]
f := Req{}
// Take notice of this sentence
f.Ext = c.QueryMap("Ext")
fmt.Println(f)
c.Status(200)
})
r.Run(":8082")
}
any update regarding this?
Description
I want to use a struct to bind map query parameter, it seems that gin doesn't support it yet.
How to reproduce
Run server:
Curl:
Environment