Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 243a831c2e | |||
| 0f890abf16 | |||
| 852468f976 | |||
| f7920fe27a | |||
| 0c37dd5576 |
@@ -2,7 +2,9 @@
|
||||
|
||||
package {{.PkgName}}
|
||||
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
import "go.mongodb.org/mongo-driver/bson"
|
||||
import "go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
import "go.mongodb.org/mongo-driver/bson/primitive"
|
||||
import "git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
|
||||
const ChecksumIDGenerator = "{{.Checksum}}" // GoExtVersion: {{.GoextVersion}}
|
||||
@@ -11,10 +13,9 @@ const ChecksumIDGenerator = "{{.Checksum}}" // GoExtVersion: {{.GoextVersion}}
|
||||
|
||||
// ================================ {{.Name}} ({{.FileRelative}}) ================================
|
||||
|
||||
func (i {{.Name}}) MarshalBSONValue() (byte, []byte, error) {
|
||||
if objId, err := bson.ObjectIDFromHex(string(i)); err == nil {
|
||||
tp, data, err := bson.MarshalValue(objId)
|
||||
return byte(tp), data, err
|
||||
func (i {{.Name}}) MarshalBSONValue() (bsontype.Type, []byte, error) {
|
||||
if objId, err := primitive.ObjectIDFromHex(string(i)); err == nil {
|
||||
return bson.MarshalValue(objId)
|
||||
} else {
|
||||
return 0, nil, exerr.New(exerr.TypeMarshalEntityID, "Failed to marshal {{.Name}}("+i.String()+") to ObjectId").Str("value", string(i)).Type("type", i).Build()
|
||||
}
|
||||
@@ -24,12 +25,12 @@ func (i {{.Name}}) String() string {
|
||||
return string(i)
|
||||
}
|
||||
|
||||
func (i {{.Name}}) ObjID() (bson.ObjectID, error) {
|
||||
return bson.ObjectIDFromHex(string(i))
|
||||
func (i {{.Name}}) ObjID() (primitive.ObjectID, error) {
|
||||
return primitive.ObjectIDFromHex(string(i))
|
||||
}
|
||||
|
||||
func (i {{.Name}}) Valid() bool {
|
||||
_, err := bson.ObjectIDFromHex(string(i))
|
||||
_, err := primitive.ObjectIDFromHex(string(i))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
@@ -49,7 +50,7 @@ func (i {{.Name}}) IsZero() bool {
|
||||
}
|
||||
|
||||
func New{{.Name}}() {{.Name}} {
|
||||
return {{.Name}}(bson.NewObjectID().Hex())
|
||||
return {{.Name}}(primitive.NewObjectID().Hex())
|
||||
}
|
||||
|
||||
{{end}}
|
||||
@@ -2,7 +2,6 @@ package cursortoken
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,9 +3,8 @@ package cursortoken
|
||||
import (
|
||||
"encoding/base32"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CTKeySort struct {
|
||||
|
||||
@@ -3,12 +3,11 @@ package exerr
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"maps"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
var reflectTypeStr = reflect.TypeFor[string]()
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
|
||||
+2
-3
@@ -3,12 +3,11 @@ package exerr
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/tst"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestJSONMarshalErrorCategory(t *testing.T) {
|
||||
|
||||
+3
-4
@@ -2,13 +2,12 @@ package exerr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/rs/xid"
|
||||
"github.com/rs/zerolog"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ExErr struct {
|
||||
|
||||
+3
-4
@@ -5,14 +5,13 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/rs/zerolog"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/rs/zerolog"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// This is a buffed up map[string]any
|
||||
|
||||
@@ -20,6 +20,7 @@ require (
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/jung-kurt/gofpdf v1.16.2
|
||||
github.com/xuri/excelize/v2 v2.10.1
|
||||
go.mongodb.org/mongo-driver v1.17.9
|
||||
golang.org/x/sync v0.20.0
|
||||
)
|
||||
|
||||
@@ -36,6 +37,7 @@ require (
|
||||
github.com/go-playground/validator/v10 v10.30.2 // indirect
|
||||
github.com/goccy/go-json v0.10.6 // indirect
|
||||
github.com/goccy/go-yaml v1.19.2 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.18.5 // indirect
|
||||
@@ -46,6 +48,7 @@ require (
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
|
||||
github.com/montanaflynn/stats v0.9.0 // indirect
|
||||
github.com/ncruces/go-strftime v1.0.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.3.0 // indirect
|
||||
github.com/quic-go/qpack v0.6.0 // indirect
|
||||
|
||||
@@ -40,6 +40,8 @@ github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU=
|
||||
github.com/goccy/go-json v0.10.6/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
|
||||
github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
|
||||
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
|
||||
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
@@ -79,6 +81,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
||||
github.com/montanaflynn/stats v0.9.0 h1:tsBJ0RXwph9BmAuFoCmqGv6e8xa0MENQ8m0ptKq29mQ=
|
||||
github.com/montanaflynn/stats v0.9.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
|
||||
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/pelletier/go-toml/v2 v2.3.0 h1:k59bC/lIZREW0/iVaQR8nDHxVq8OVlIzYCOJf421CaM=
|
||||
@@ -136,6 +140,8 @@ github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9/go.mod h1:WwHg+CVyzlv/T
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.mongodb.org/mongo-driver v1.17.9 h1:IexDdCuuNJ3BHrELgBlyaH9p60JXAvdzWR128q+U5tU=
|
||||
go.mongodb.org/mongo-driver v1.17.9/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.1 h1:j2U/Qp+wvueSpqitLCSZPT/+ZpVc1xzuwdHWwl7d8ro=
|
||||
go.mongodb.org/mongo-driver/v2 v2.5.1/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
|
||||
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.636"
|
||||
const GoextVersion = "0.0.633"
|
||||
|
||||
const GoextVersionTimestamp = "2026-04-26T14:53:24+0200"
|
||||
const GoextVersionTimestamp = "2026-04-13T16:12:09+0200"
|
||||
|
||||
@@ -108,11 +108,11 @@ func (u unmarshalerText) MarshalText() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (u *unmarshalerText) UnmarshalText(b []byte) error {
|
||||
pos := bytes.IndexByte(b, ':')
|
||||
if pos == -1 {
|
||||
before, after, ok := bytes.Cut(b, []byte{':'})
|
||||
if !ok {
|
||||
return errors.New("missing separator")
|
||||
}
|
||||
u.A, u.B = string(b[:pos]), string(b[pos+1:])
|
||||
u.A, u.B = string(before), string(after)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ type ustructText struct {
|
||||
type u8marshal uint8
|
||||
|
||||
func (u8 u8marshal) MarshalText() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf("u%d", u8)), nil
|
||||
return fmt.Appendf(nil, "u%d", u8), nil
|
||||
}
|
||||
|
||||
var errMissingU8Prefix = errors.New("missing 'u' prefix")
|
||||
@@ -275,7 +275,7 @@ func (unexportedWithMethods) F() {}
|
||||
type byteWithMarshalJSON byte
|
||||
|
||||
func (b byteWithMarshalJSON) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"Z%.2x"`, byte(b))), nil
|
||||
return fmt.Appendf(nil, `"Z%.2x"`, byte(b)), nil
|
||||
}
|
||||
|
||||
func (b *byteWithMarshalJSON) UnmarshalJSON(data []byte) error {
|
||||
@@ -303,7 +303,7 @@ func (b *byteWithPtrMarshalJSON) UnmarshalJSON(data []byte) error {
|
||||
type byteWithMarshalText byte
|
||||
|
||||
func (b byteWithMarshalText) MarshalText() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`Z%.2x`, byte(b))), nil
|
||||
return fmt.Appendf(nil, `Z%.2x`, byte(b)), nil
|
||||
}
|
||||
|
||||
func (b *byteWithMarshalText) UnmarshalText(data []byte) error {
|
||||
@@ -331,7 +331,7 @@ func (b *byteWithPtrMarshalText) UnmarshalText(data []byte) error {
|
||||
type intWithMarshalJSON int
|
||||
|
||||
func (b intWithMarshalJSON) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"Z%.2x"`, int(b))), nil
|
||||
return fmt.Appendf(nil, `"Z%.2x"`, int(b)), nil
|
||||
}
|
||||
|
||||
func (b *intWithMarshalJSON) UnmarshalJSON(data []byte) error {
|
||||
@@ -359,7 +359,7 @@ func (b *intWithPtrMarshalJSON) UnmarshalJSON(data []byte) error {
|
||||
type intWithMarshalText int
|
||||
|
||||
func (b intWithMarshalText) MarshalText() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`Z%.2x`, int(b))), nil
|
||||
return fmt.Appendf(nil, `Z%.2x`, int(b)), nil
|
||||
}
|
||||
|
||||
func (b *intWithMarshalText) UnmarshalText(data []byte) error {
|
||||
|
||||
+5
-13
@@ -177,7 +177,7 @@ type IndentOpt struct {
|
||||
|
||||
// MarshalSafeCollections is like Marshal except it will marshal nil maps and
|
||||
// slices as '{}' and '[]' respectfully instead of 'null'
|
||||
func MarshalSafeCollections(v interface{}, nilSafeSlices bool, nilSafeMaps bool, indent *IndentOpt, filter *string) ([]byte, error) {
|
||||
func MarshalSafeCollections(v any, nilSafeSlices bool, nilSafeMaps bool, indent *IndentOpt, filter *string) ([]byte, error) {
|
||||
e := &encodeState{}
|
||||
err := e.marshal(v, encOpts{escapeHTML: true, nilSafeSlices: nilSafeSlices, nilSafeMaps: nilSafeMaps, filter: filter})
|
||||
if err != nil {
|
||||
@@ -891,7 +891,7 @@ func (se sliceEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
|
||||
// Here we use a struct to memorize the pointer to the first element of the slice
|
||||
// and its length.
|
||||
ptr := struct {
|
||||
ptr interface{} // always an unsafe.Pointer, but avoids a dependency on package unsafe
|
||||
ptr any // always an unsafe.Pointer, but avoids a dependency on package unsafe
|
||||
len int
|
||||
}{v.UnsafePointer(), v.Len()}
|
||||
if _, ok := e.ptrSeen[ptr]; ok {
|
||||
@@ -923,7 +923,7 @@ type arrayEncoder struct {
|
||||
func (ae arrayEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
|
||||
e.WriteByte('[')
|
||||
n := v.Len()
|
||||
for i := 0; i < n; i++ {
|
||||
for i := range n {
|
||||
if i > 0 {
|
||||
e.WriteByte(',')
|
||||
}
|
||||
@@ -1075,10 +1075,7 @@ func appendString[Bytes []byte | string](dst []byte, src Bytes, escapeHTML bool)
|
||||
// For now, cast only a small portion of byte slices to a string
|
||||
// so that it can be stack allocated. This slows down []byte slightly
|
||||
// due to the extra copy, but keeps string performance roughly the same.
|
||||
n := len(src) - i
|
||||
if n > utf8.UTFMax {
|
||||
n = utf8.UTFMax
|
||||
}
|
||||
n := min(len(src)-i, utf8.UTFMax)
|
||||
c, size := utf8.DecodeRuneInString(string(src[i : i+n]))
|
||||
if c == utf8.RuneError && size == 1 {
|
||||
dst = append(dst, src[start:i]...)
|
||||
@@ -1130,12 +1127,7 @@ type field struct {
|
||||
type jsonfilter []string
|
||||
|
||||
func (j jsonfilter) Contains(t string) bool {
|
||||
for _, tag := range j {
|
||||
if t == tag {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(j, t)
|
||||
}
|
||||
|
||||
// typeFields returns a list of fields that JSON should recognize for the given type.
|
||||
|
||||
+14
-15
@@ -41,7 +41,7 @@ type Optionals struct {
|
||||
Uo uint `json:"uo,omitempty"`
|
||||
|
||||
Str struct{} `json:"str"`
|
||||
Sto struct{} `json:"sto,omitempty"`
|
||||
Sto struct{} `json:"sto"`
|
||||
}
|
||||
|
||||
func TestOmitEmpty(t *testing.T) {
|
||||
@@ -1166,8 +1166,7 @@ func TestMarshalUncommonFieldNames(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMarshalerError(t *testing.T) {
|
||||
s := "test variable"
|
||||
st := reflect.TypeOf(s)
|
||||
st := reflect.TypeFor[string]()
|
||||
const errText = "json: test error"
|
||||
|
||||
tests := []struct {
|
||||
@@ -1222,18 +1221,18 @@ func TestIssue63379(t *testing.T) {
|
||||
|
||||
func TestMarshalSafeCollections(t *testing.T) {
|
||||
var (
|
||||
nilSlice []interface{}
|
||||
pNilSlice *[]interface{}
|
||||
nilMap map[string]interface{}
|
||||
pNilMap *map[string]interface{}
|
||||
nilSlice []any
|
||||
pNilSlice *[]any
|
||||
nilMap map[string]any
|
||||
pNilMap *map[string]any
|
||||
)
|
||||
|
||||
type (
|
||||
nilSliceStruct struct {
|
||||
NilSlice []interface{} `json:"nil_slice"`
|
||||
NilSlice []any `json:"nil_slice"`
|
||||
}
|
||||
nilMapStruct struct {
|
||||
NilMap map[string]interface{} `json:"nil_map"`
|
||||
NilMap map[string]any `json:"nil_map"`
|
||||
}
|
||||
testWithFilter struct {
|
||||
Test1 string `json:"test1" jsonfilter:"FILTERONE"`
|
||||
@@ -1242,19 +1241,19 @@ func TestMarshalSafeCollections(t *testing.T) {
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
in interface{}
|
||||
in any
|
||||
want string
|
||||
}{
|
||||
{nilSlice, "[]"},
|
||||
{[]interface{}{}, "[]"},
|
||||
{make([]interface{}, 0), "[]"},
|
||||
{[]any{}, "[]"},
|
||||
{make([]any, 0), "[]"},
|
||||
{[]int{1, 2, 3}, "[1,2,3]"},
|
||||
{pNilSlice, "null"},
|
||||
{nilSliceStruct{}, "{\"nil_slice\":[]}"},
|
||||
{nilMap, "{}"},
|
||||
{map[string]interface{}{}, "{}"},
|
||||
{make(map[string]interface{}, 0), "{}"},
|
||||
{map[string]interface{}{"1": 1, "2": 2, "3": 3}, "{\"1\":1,\"2\":2,\"3\":3}"},
|
||||
{map[string]any{}, "{}"},
|
||||
{make(map[string]any, 0), "{}"},
|
||||
{map[string]any{"1": 1, "2": 2, "3": 3}, "{\"1\":1,\"2\":2,\"3\":3}"},
|
||||
{pNilMap, "null"},
|
||||
{nilMapStruct{}, "{\"nil_map\":{}}"},
|
||||
{testWithFilter{}, "{\"test1\":\"\"}"},
|
||||
|
||||
+4
-4
@@ -28,10 +28,10 @@ func FuzzUnmarshalJSON(f *testing.F) {
|
||||
}`))
|
||||
|
||||
f.Fuzz(func(t *testing.T, b []byte) {
|
||||
for _, typ := range []func() interface{}{
|
||||
func() interface{} { return new(interface{}) },
|
||||
func() interface{} { return new(map[string]interface{}) },
|
||||
func() interface{} { return new([]interface{}) },
|
||||
for _, typ := range []func() any{
|
||||
func() any { return new(any) },
|
||||
func() any { return new(map[string]any) },
|
||||
func() any { return new([]any) },
|
||||
} {
|
||||
i := typ()
|
||||
if err := Unmarshal(b, i); err != nil {
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ func appendCompact(dst, src []byte, escape bool) ([]byte, error) {
|
||||
func appendNewline(dst []byte, prefix, indent string, depth int) []byte {
|
||||
dst = append(dst, '\n')
|
||||
dst = append(dst, prefix...)
|
||||
for i := 0; i < depth; i++ {
|
||||
for range depth {
|
||||
dst = append(dst, indent...)
|
||||
}
|
||||
return dst
|
||||
|
||||
+3
-12
@@ -210,10 +210,7 @@ func diff(t *testing.T, a, b []byte) {
|
||||
t.Helper()
|
||||
for i := 0; ; i++ {
|
||||
if i >= len(a) || i >= len(b) || a[i] != b[i] {
|
||||
j := i - 10
|
||||
if j < 0 {
|
||||
j = 0
|
||||
}
|
||||
j := max(i-10, 0)
|
||||
t.Errorf("diverge at %d: «%s» vs «%s»", i, trim(a[j:]), trim(b[j:]))
|
||||
return
|
||||
}
|
||||
@@ -274,10 +271,7 @@ func genString(stddev float64) string {
|
||||
}
|
||||
|
||||
func genArray(n int) []any {
|
||||
f := int(math.Abs(rand.NormFloat64()) * math.Min(10, float64(n/2)))
|
||||
if f > n {
|
||||
f = n
|
||||
}
|
||||
f := min(int(math.Abs(rand.NormFloat64())*math.Min(10, float64(n/2))), n)
|
||||
if f < 1 {
|
||||
f = 1
|
||||
}
|
||||
@@ -289,10 +283,7 @@ func genArray(n int) []any {
|
||||
}
|
||||
|
||||
func genMap(n int) map[string]any {
|
||||
f := int(math.Abs(rand.NormFloat64()) * math.Min(10, float64(n/2)))
|
||||
if f > n {
|
||||
f = n
|
||||
}
|
||||
f := min(int(math.Abs(rand.NormFloat64())*math.Min(10, float64(n/2))), n)
|
||||
if n > 0 && f == 0 {
|
||||
f = 1
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// https://datatracker.ietf.org/doc/html/rfc2822
|
||||
func encodeMimeMail(from string, recipients []string, cc []string, bcc []string, replyTo []string, subject string, body MailBody, attachments []MailAttachment) string {
|
||||
func encodeMimeMail(from string, recipients []string, cc []string, bcc []string, subject string, body MailBody, attachments []MailAttachment) string {
|
||||
|
||||
data := make([]string, 0, 32)
|
||||
|
||||
@@ -22,9 +22,6 @@ func encodeMimeMail(from string, recipients []string, cc []string, bcc []string,
|
||||
if len(bcc) > 0 {
|
||||
data = append(data, "Bcc: "+strings.Join(langext.ArrMap(bcc, func(v string) string { return mime.QEncoding.Encode("UTF-8", v) }), ", "))
|
||||
}
|
||||
if len(replyTo) > 0 {
|
||||
data = append(data, "Reply-To: "+strings.Join(langext.ArrMap(replyTo, func(v string) string { return mime.QEncoding.Encode("UTF-8", v) }), ", "))
|
||||
}
|
||||
data = append(data, "Subject: "+mime.QEncoding.Encode("UTF-8", subject))
|
||||
|
||||
hasInlineAttachments := langext.ArrAny(attachments, func(v MailAttachment) bool { return v.IsInline })
|
||||
|
||||
@@ -13,7 +13,6 @@ func TestEncodeMimeMail(t *testing.T) {
|
||||
[]string{"trash@mikescher.de"},
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
"Hello Test Mail",
|
||||
MailBody{Plain: "Plain Text"},
|
||||
nil)
|
||||
@@ -28,7 +27,6 @@ func TestEncodeMimeMail2(t *testing.T) {
|
||||
[]string{"trash@mikescher.de"},
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
"Hello Test Mail (alternative)",
|
||||
MailBody{
|
||||
Plain: "Plain Text",
|
||||
@@ -46,7 +44,6 @@ func TestEncodeMimeMail3(t *testing.T) {
|
||||
[]string{"trash@mikescher.de"},
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
"Hello Test Mail (alternative)",
|
||||
MailBody{
|
||||
HTML: "<html><body><u>Non</u> Pl<i>ai</i>n T<b>ex</b>t</body></html>",
|
||||
@@ -67,7 +64,6 @@ func TestEncodeMimeMail4(t *testing.T) {
|
||||
[]string{"trash@mikescher.de"},
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
"Hello Test Mail (inline)",
|
||||
MailBody{
|
||||
HTML: "<html><body><u>Non</u> Pl<i>ai</i>n T<b>ex</b>t</body></html>",
|
||||
|
||||
@@ -19,9 +19,9 @@ type MailRef struct {
|
||||
LabelIDs []string `json:"labelIds"`
|
||||
}
|
||||
|
||||
func (c *client) SendMail(ctx context.Context, from string, recipients []string, cc []string, bcc []string, replyTo []string, subject string, body MailBody, attachments []MailAttachment) (MailRef, error) {
|
||||
func (c *client) SendMail(ctx context.Context, from string, recipients []string, cc []string, bcc []string, subject string, body MailBody, attachments []MailAttachment) (MailRef, error) {
|
||||
|
||||
mm := encodeMimeMail(from, recipients, cc, bcc, replyTo, subject, body, attachments)
|
||||
mm := encodeMimeMail(from, recipients, cc, bcc, subject, body, attachments)
|
||||
|
||||
tok, err := c.oauth.AccessToken()
|
||||
if err != nil {
|
||||
|
||||
@@ -36,7 +36,6 @@ func TestSendMail1(t *testing.T) {
|
||||
[]string{"trash@mikescher.de"},
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
"Hello Test Mail",
|
||||
MailBody{Plain: "Plain Text"},
|
||||
nil)
|
||||
@@ -67,7 +66,6 @@ func TestSendMail2(t *testing.T) {
|
||||
[]string{"trash@mikescher.de"},
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
"Hello Test Mail (alternative)",
|
||||
MailBody{
|
||||
Plain: "Plain Text",
|
||||
@@ -101,7 +99,6 @@ func TestSendMail3(t *testing.T) {
|
||||
[]string{"trash@mikescher.de"},
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
"Hello Test Mail (attach)",
|
||||
MailBody{
|
||||
HTML: "<html><body><u>Non</u> Pl<i>ai</i>n T<b>ex</b>t</body></html>",
|
||||
@@ -138,7 +135,6 @@ func TestSendMail4(t *testing.T) {
|
||||
[]string{"trash@mikescher.de"},
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
"Hello Test Mail (inline)",
|
||||
MailBody{
|
||||
HTML: "<html><body><u>Non</u> Pl<i>ai</i>n T<b>ex</b>t</body></html>",
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type GoogleClient interface {
|
||||
SendMail(ctx context.Context, from string, recipients []string, cc []string, bcc []string, replyTo []string, subject string, body MailBody, attachments []MailAttachment) (MailRef, error)
|
||||
SendMail(ctx context.Context, from string, recipients []string, cc []string, bcc []string, subject string, body MailBody, attachments []MailAttachment) (MailRef, error)
|
||||
}
|
||||
|
||||
type client struct {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package mongoext
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// ProjectionFromStruct automatically generated a mongodb projection for a struct
|
||||
|
||||
@@ -2,7 +2,6 @@ package pagination
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
@@ -3,13 +3,12 @@ package reflectext
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
var primitiveSerializer = map[reflect.Type]genSerializer{
|
||||
|
||||
+1
-2
@@ -4,11 +4,10 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type Date struct {
|
||||
|
||||
@@ -4,9 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RFC3339NanoTime time.Time
|
||||
|
||||
+1
-2
@@ -4,10 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/timeext"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SecondsF64 time.Duration
|
||||
|
||||
+1
-2
@@ -4,10 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type UnixTime time.Time
|
||||
|
||||
@@ -4,10 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type UnixMilliTime time.Time
|
||||
|
||||
+1
-2
@@ -4,10 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type UnixNanoTime time.Time
|
||||
|
||||
@@ -51,7 +51,10 @@ func GetIsoWeekCount(year int) int {
|
||||
w2 -= 1
|
||||
w3 -= 1
|
||||
|
||||
w := max(w3, max(w2, w1))
|
||||
w := max(w2, w1)
|
||||
if w3 > w {
|
||||
w = w3
|
||||
}
|
||||
|
||||
return w
|
||||
}
|
||||
|
||||
+1
-2
@@ -2,12 +2,11 @@ package wmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
ct "git.blackforestbytes.com/BlackForestBytes/goext/cursortoken"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type EntityID interface {
|
||||
|
||||
@@ -2,7 +2,6 @@ package wmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,6 @@ package wmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
|
||||
@@ -2,7 +2,6 @@ package wmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
|
||||
+5
-20
@@ -2,13 +2,12 @@ package wmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"iter"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
"iter"
|
||||
)
|
||||
|
||||
func (c *Coll[TData]) createFindQuery(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (*mongo.Cursor, error) {
|
||||
@@ -52,23 +51,18 @@ func (c *Coll[TData]) createFindQuery(ctx context.Context, filter bson.M, opts .
|
||||
}
|
||||
}
|
||||
|
||||
convOpts := make([]*options.AggregateOptionsBuilder, 0, len(opts))
|
||||
convOpts := make([]options.Lister[options.AggregateOptions], 0, len(opts))
|
||||
for _, v := range opts {
|
||||
vConv, err := convertFindOpt(v)
|
||||
if err != nil {
|
||||
return nil, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build()
|
||||
}
|
||||
convOpts = append(convOpts, vConv)
|
||||
}
|
||||
|
||||
convOptsLister := make([]options.Lister[options.AggregateOptions], 0, len(convOpts))
|
||||
for _, v := range convOpts {
|
||||
if v != nil {
|
||||
convOptsLister = append(convOptsLister, v)
|
||||
if vConv != nil {
|
||||
convOpts = append(convOpts, vConv)
|
||||
}
|
||||
}
|
||||
|
||||
cursor, err := c.coll.Aggregate(ctx, pipeline, convOptsLister...)
|
||||
cursor, err := c.coll.Aggregate(ctx, pipeline, convOpts...)
|
||||
if err != nil {
|
||||
return nil, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build()
|
||||
}
|
||||
@@ -173,21 +167,12 @@ func convertFindOpt(v *options.FindOptions) (*options.AggregateOptionsBuilder, e
|
||||
if v.Hint != nil {
|
||||
r.SetHint(v.Hint)
|
||||
}
|
||||
if v.Max != nil {
|
||||
return nil, exerr.New(exerr.TypeMongoInvalidOpt, "Invalid option 'Max' (cannot convert to AggregateOptions)").Build()
|
||||
}
|
||||
if v.MaxAwaitTime != nil {
|
||||
r.SetMaxAwaitTime(*v.MaxAwaitTime)
|
||||
}
|
||||
if v.Min != nil {
|
||||
return nil, exerr.New(exerr.TypeMongoInvalidOpt, "Invalid option 'Min' (cannot convert to AggregateOptions)").Build()
|
||||
}
|
||||
if v.NoCursorTimeout != nil {
|
||||
return nil, exerr.New(exerr.TypeMongoInvalidOpt, "Invalid option 'NoCursorTimeout' (cannot convert to AggregateOptions)").Build()
|
||||
}
|
||||
if v.OplogReplay != nil {
|
||||
return nil, exerr.New(exerr.TypeMongoInvalidOpt, "Invalid option 'OplogReplay' (cannot convert to AggregateOptions)").Build()
|
||||
}
|
||||
if v.ReturnKey != nil {
|
||||
return nil, exerr.New(exerr.TypeMongoInvalidOpt, "Invalid option 'ReturnKey' (cannot convert to AggregateOptions)").Build()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package wmo
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
@@ -2,7 +2,6 @@ package wmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
+1
-2
@@ -2,13 +2,12 @@ package wmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"iter"
|
||||
|
||||
ct "git.blackforestbytes.com/BlackForestBytes/goext/cursortoken"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"iter"
|
||||
)
|
||||
|
||||
func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int, inTok ct.CursorToken) ([]TData, ct.CursorToken, error) {
|
||||
|
||||
@@ -2,13 +2,12 @@ package wmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"iter"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
pag "git.blackforestbytes.com/BlackForestBytes/goext/pagination"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"iter"
|
||||
)
|
||||
|
||||
func (c *Coll[TData]) Paginate(ctx context.Context, filter pag.MongoFilter, page int, limit *int) ([]TData, pag.Pagination, error) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package wmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
|
||||
+4
-3
@@ -1,11 +1,12 @@
|
||||
package wpdf
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/rext"
|
||||
"regexp"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Column specifier:
|
||||
@@ -298,7 +299,7 @@ func (b *TableBuilder) calculateColumns() []float64 {
|
||||
|
||||
if remainingWidth > 0.01 {
|
||||
rmSub := 0.0
|
||||
for i, _ := range columnDef {
|
||||
for i := range columnDef {
|
||||
if frColumnWeights[i] != 0 {
|
||||
addW := (remainingWidth / float64(frColumnWidthCount)) * frColumnWeights[i]
|
||||
rmSub += addW
|
||||
|
||||
Reference in New Issue
Block a user