v0.0.492
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 5m32s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 5m32s
This commit is contained in:
9
ginext/jsonFilter.go
Normal file
9
ginext/jsonFilter.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package ginext
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
var jsonFilterKey = "goext.jsonfilter"
|
||||
|
||||
func SetJSONFilter(g *gin.Context, filter string) {
|
||||
g.Set(jsonFilterKey, filter)
|
||||
}
|
@@ -15,7 +15,7 @@ type jsonHTTPResponse struct {
|
||||
|
||||
func (j jsonHTTPResponse) jsonRenderer(g *gin.Context) json.GoJsonRender {
|
||||
var f *string
|
||||
if jsonfilter := g.GetString("goext.jsonfilter"); jsonfilter != "" {
|
||||
if jsonfilter := g.GetString(jsonFilterKey); jsonfilter != "" {
|
||||
f = &jsonfilter
|
||||
}
|
||||
return json.GoJsonRender{Data: j.data, NilSafeSlices: true, NilSafeMaps: true, Filter: f}
|
||||
|
@@ -57,7 +57,7 @@ func (w *GinRoutesWrapper) Use(middleware ...gin.HandlerFunc) *GinRoutesWrapper
|
||||
}
|
||||
|
||||
func (w *GinRoutesWrapper) WithJSONFilter(filter string) *GinRoutesWrapper {
|
||||
return w.Use(func(g *gin.Context) { g.Set("goext.jsonfilter", filter) })
|
||||
return w.Use(func(g *gin.Context) { g.Set(jsonFilterKey, filter) })
|
||||
}
|
||||
|
||||
func (w *GinRoutesWrapper) GET(relativePath string) *GinRouteBuilder {
|
||||
@@ -112,7 +112,7 @@ func (w *GinRouteBuilder) Use(middleware ...gin.HandlerFunc) *GinRouteBuilder {
|
||||
}
|
||||
|
||||
func (w *GinRouteBuilder) WithJSONFilter(filter string) *GinRouteBuilder {
|
||||
return w.Use(func(g *gin.Context) { g.Set("goext.jsonfilter", filter) })
|
||||
return w.Use(func(g *gin.Context) { g.Set(jsonFilterKey, filter) })
|
||||
}
|
||||
|
||||
func (w *GinRouteBuilder) Handle(handler WHandlerFunc) {
|
||||
|
Reference in New Issue
Block a user