Compare commits

...

4 Commits

Author SHA1 Message Date
19c7e22ced v0.0.514 fix mongo filter where the primary sort key is null in db (fallback to secondary)
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
2024-09-16 17:39:18 +02:00
9f883b458f v0.0.513
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 4m55s
2024-09-16 15:27:32 +02:00
1f456c5134 v0.0.512
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 5m6s
2024-09-15 21:25:21 +02:00
d7fbef37db v0.0.511
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m10s
2024-09-15 18:22:07 +02:00
5 changed files with 31 additions and 12 deletions

View File

@@ -38,6 +38,13 @@ func (ee *ExErr) Error() string {
// Unwrap must be implemented so that some error.XXX methods work // Unwrap must be implemented so that some error.XXX methods work
func (ee *ExErr) Unwrap() error { func (ee *ExErr) Unwrap() error {
if ee.OriginalError == nil { if ee.OriginalError == nil {
if ee.WrappedErr != nil {
if werr, ok := ee.WrappedErr.(error); ok {
return werr
}
}
return nil // this is neccessary - otherwise we return a wrapped nil and the `x == nil` comparison fails (= panic in errors.Is and other failures) return nil // this is neccessary - otherwise we return a wrapped nil and the `x == nil` comparison fails (= panic in errors.Is and other failures)
} }
return ee.OriginalError return ee.OriginalError

View File

@@ -7,10 +7,11 @@ import (
) )
type jsonHTTPResponse struct { type jsonHTTPResponse struct {
statusCode int statusCode int
data any data any
headers []headerval headers []headerval
cookies []cookieval cookies []cookieval
filterOverride *string
} }
func (j jsonHTTPResponse) jsonRenderer(g *gin.Context) json.GoJsonRender { 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 != "" { if jsonfilter := g.GetString(jsonFilterKey); jsonfilter != "" {
f = &jsonfilter f = &jsonfilter
} }
if j.filterOverride != nil {
f = j.filterOverride
}
return json.GoJsonRender{Data: j.data, NilSafeSlices: true, NilSafeMaps: true, Filter: f} 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 { func JSON(sc int, data any) HTTPResponse {
return &jsonHTTPResponse{statusCode: sc, data: data} return &jsonHTTPResponse{statusCode: sc, data: data}
} }
func JSONWithFilter(sc int, data any, f string) HTTPResponse {
return &jsonHTTPResponse{statusCode: sc, data: data, filterOverride: &f}
}

View File

@@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.510" const GoextVersion = "0.0.514"
const GoextVersionTimestamp = "2024-09-13T18:06:49+0200" const GoextVersionTimestamp = "2024-09-16T17:39:18+0200"

View File

@@ -788,7 +788,7 @@ FieldLoop:
if f.omitEmpty && isEmptyValue(fv) { if f.omitEmpty && isEmptyValue(fv) {
continue continue
} else if opts.filter != nil && !matchesJSONFilter(f.jsonfilter, *opts.filter) { } else if !matchesJSONFilter(f.jsonfilter, opts.filter) {
continue continue
} }
e.WriteByte(next) 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 { 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] == "-" { if len(filter) == 1 && filter[0] == "-" {
return false return false
} }
if filter.Contains(value) { if filter.Contains(*value) {
return true return true
} }

View File

@@ -215,7 +215,7 @@ func createPaginationPipeline[TData any](coll *Coll[TData], token ct.CursorToken
// the conflict-resolution condition, for entries with the _same_ <field> as the $primary we take the ones with a greater $secondary (= newer) // the conflict-resolution condition, for entries with the _same_ <field> as the $primary we take the ones with a greater $secondary (= newer)
cond = append(cond, bson.M{"$and": bson.A{ cond = append(cond, bson.M{"$and": bson.A{
bson.M{fieldPrimary: valuePrimary}, bson.M{"$or": bson.A{bson.M{fieldPrimary: valuePrimary}, bson.M{fieldPrimary: nil}}},
bson.M{*fieldSecondary: bson.M{"$gt": valueSecondary}}, bson.M{*fieldSecondary: bson.M{"$gt": valueSecondary}},
}}) }})
@@ -225,7 +225,7 @@ func createPaginationPipeline[TData any](coll *Coll[TData], token ct.CursorToken
// the conflict-resolution condition, for entries with the _same_ <field> as the $primary we take the ones with a smaller $secondary (= older) // the conflict-resolution condition, for entries with the _same_ <field> as the $primary we take the ones with a smaller $secondary (= older)
cond = append(cond, bson.M{"$and": bson.A{ cond = append(cond, bson.M{"$and": bson.A{
bson.M{fieldPrimary: valuePrimary}, bson.M{"$or": bson.A{bson.M{fieldPrimary: valuePrimary}, bson.M{fieldPrimary: nil}}},
bson.M{*fieldSecondary: bson.M{"$lt": valueSecondary}}, bson.M{*fieldSecondary: bson.M{"$lt": valueSecondary}},
}}) }})