Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
1f456c5134
|
|||
d7fbef37db
|
@@ -7,10 +7,11 @@ import (
|
||||
)
|
||||
|
||||
type jsonHTTPResponse struct {
|
||||
statusCode int
|
||||
data any
|
||||
headers []headerval
|
||||
cookies []cookieval
|
||||
statusCode int
|
||||
data any
|
||||
headers []headerval
|
||||
cookies []cookieval
|
||||
filterOverride *string
|
||||
}
|
||||
|
||||
func (j jsonHTTPResponse) jsonRenderer(g *gin.Context) json.GoJsonRender {
|
||||
@@ -18,6 +19,9 @@ func (j jsonHTTPResponse) jsonRenderer(g *gin.Context) json.GoJsonRender {
|
||||
if jsonfilter := g.GetString(jsonFilterKey); jsonfilter != "" {
|
||||
f = &jsonfilter
|
||||
}
|
||||
if j.filterOverride != nil {
|
||||
f = j.filterOverride
|
||||
}
|
||||
return json.GoJsonRender{Data: j.data, NilSafeSlices: true, NilSafeMaps: true, Filter: f}
|
||||
}
|
||||
|
||||
@@ -68,3 +72,7 @@ func (j jsonHTTPResponse) Headers() []string {
|
||||
func JSON(sc int, data any) HTTPResponse {
|
||||
return &jsonHTTPResponse{statusCode: sc, data: data}
|
||||
}
|
||||
|
||||
func JSONWithFilter(sc int, data any, f string) HTTPResponse {
|
||||
return &jsonHTTPResponse{statusCode: sc, data: data, filterOverride: &f}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.510"
|
||||
const GoextVersion = "0.0.512"
|
||||
|
||||
const GoextVersionTimestamp = "2024-09-13T18:06:49+0200"
|
||||
const GoextVersionTimestamp = "2024-09-15T21:25:21+0200"
|
||||
|
@@ -788,7 +788,7 @@ FieldLoop:
|
||||
|
||||
if f.omitEmpty && isEmptyValue(fv) {
|
||||
continue
|
||||
} else if opts.filter != nil && !matchesJSONFilter(f.jsonfilter, *opts.filter) {
|
||||
} else if !matchesJSONFilter(f.jsonfilter, opts.filter) {
|
||||
continue
|
||||
}
|
||||
e.WriteByte(next)
|
||||
@@ -808,16 +808,20 @@ FieldLoop:
|
||||
}
|
||||
}
|
||||
|
||||
func matchesJSONFilter(filter jsonfilter, value string) bool {
|
||||
func matchesJSONFilter(filter jsonfilter, value *string) bool {
|
||||
if len(filter) == 0 {
|
||||
return true
|
||||
return true // no filter in struct
|
||||
}
|
||||
|
||||
if value == nil || *value == "" {
|
||||
return false // no filter set, but struct has filter, return false
|
||||
}
|
||||
|
||||
if len(filter) == 1 && filter[0] == "-" {
|
||||
return false
|
||||
}
|
||||
|
||||
if filter.Contains(value) {
|
||||
if filter.Contains(*value) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user