Skip to content

Commit

Permalink
feat(context): methods to get nested map from query string
Browse files Browse the repository at this point in the history
  • Loading branch information
dorzepowski committed Aug 27, 2024
1 parent cc4e114 commit 8f79761
Show file tree
Hide file tree
Showing 4 changed files with 770 additions and 0 deletions.
15 changes: 15 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/gin-contrib/sse"
"github.com/gin-gonic/gin/binding"
"github.com/gin-gonic/gin/internal/query"
"github.com/gin-gonic/gin/render"
)

Expand Down Expand Up @@ -504,6 +505,20 @@ func (c *Context) GetQueryMap(key string) (map[string]string, bool) {
return c.get(c.queryCache, key)
}

// ShouldGetQueryNestedMap returns a map from query params.
// In contrast to QueryMap it handles nesting in query maps like key[foo][bar]=value.
func (c *Context) ShouldGetQueryNestedMap() (dicts map[string]interface{}, err error) {
return c.ShouldGetQueryNestedMapForKey("")
}

// ShouldGetQueryNestedMapForKey returns a map from query params for a given query key.
// In contrast to QueryMap it handles nesting in query maps like key[foo][bar]=value.
// Similar to ShouldGetQueryNestedMap but it returns only the map for the given key.
func (c *Context) ShouldGetQueryNestedMapForKey(key string) (dicts map[string]interface{}, err error) {
q := c.Request.URL.Query()
return query.GetMap(q, key)
}

// PostForm returns the specified key from a POST urlencoded form or multipart form
// when it exists, otherwise it returns an empty string `("")`.
func (c *Context) PostForm(key string) (value string) {
Expand Down
Loading

0 comments on commit 8f79761

Please sign in to comment.