Compare commits

...

6 Commits

Author SHA1 Message Date
422bbd8593 v0.0.397 added wmo.IColl inetrface for tim
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 4m2s
2024-03-04 12:17:10 +01:00
3956675e04 v0.0.396 sq.ConverterRFCSecondsF64ToString
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m2s
2024-02-28 14:28:48 +01:00
10c3780b52 v0.0.395 MapMerge
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m14s
2024-02-27 13:42:06 +01:00
8edc067a3b v0.0.394
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m31s
2024-02-21 18:40:42 +01:00
1007f2c834 v0.0.393
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m19s
2024-02-21 18:33:18 +01:00
c25da03217 v0.0.392
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
2024-02-21 18:32:06 +01:00
8 changed files with 237 additions and 6 deletions

8
go.mod
View File

@@ -9,13 +9,13 @@ require (
github.com/rs/xid v1.5.0
github.com/rs/zerolog v1.32.0
go.mongodb.org/mongo-driver v1.14.0
golang.org/x/crypto v0.19.0
golang.org/x/crypto v0.20.0
golang.org/x/sys v0.17.0
golang.org/x/term v0.17.0
)
require (
github.com/bytedance/sonic v1.11.0 // indirect
github.com/bytedance/sonic v1.11.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
@@ -23,12 +23,12 @@ require (
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.18.0 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect

10
go.sum
View File

@@ -4,6 +4,10 @@ github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZF
github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
github.com/bytedance/sonic v1.11.0 h1:FwNNv6Vu4z2Onf1++LNzxB/QhitD8wuTdpZzMTGITWo=
github.com/bytedance/sonic v1.11.0/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
github.com/bytedance/sonic v1.11.1 h1:JC0+6c9FoWYYxakaoa+c5QTtJeiSZNeByOBhXtAFSn4=
github.com/bytedance/sonic v1.11.1/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
github.com/bytedance/sonic v1.11.2 h1:ywfwo0a/3j9HR8wsYGWsIWl2mvRsI950HyoxiBERw5A=
github.com/bytedance/sonic v1.11.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
@@ -37,6 +41,8 @@ github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ
github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-playground/validator/v10 v10.18.0 h1:BvolUXjp4zuvkZ5YN5t7ebzbhlUtPsPm2S9NAZ5nl9U=
github.com/go-playground/validator/v10 v10.18.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
@@ -63,6 +69,8 @@ github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI=
github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
@@ -147,6 +155,8 @@ golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg=
golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=

View File

@@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.391"
const GoextVersion = "0.0.397"
const GoextVersionTimestamp = "2024-02-21T16:18:04+0100"
const GoextVersionTimestamp = "2024-03-04T12:17:10+0100"

View File

@@ -71,3 +71,19 @@ func ForceMap[K comparable, V any](v map[K]V) map[K]V {
return v
}
}
func MapMerge[K comparable, V any](base map[K]V, arr ...map[K]V) map[K]V {
res := make(map[K]V, len(base)*(1+len(arr)))
for k, v := range base {
res[k] = v
}
for _, m := range arr {
for k, v := range m {
res[k] = v
}
}
return res
}

148
rfctime/time.go Normal file
View File

@@ -0,0 +1,148 @@
package rfctime
import (
"fmt"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"strconv"
"strings"
"time"
)
type Time struct {
Hour int
Minute int
Second int
NanoSecond int
}
func (t Time) Serialize() string {
return fmt.Sprintf("%04d:%02d:%02d.%09d", t.Hour, t.Minute, t.Second, t.NanoSecond)
}
func (t Time) SerializeShort() string {
if t.NanoSecond == 0 && t.Second == 0 {
return fmt.Sprintf("%02d:%02d", t.Hour, t.Minute)
} else if t.NanoSecond == 0 {
return fmt.Sprintf("%02d:%02d:%02d", t.Hour, t.Minute, t.Second)
} else {
return fmt.Sprintf("%02d:%02d:%02d.%09d", t.Hour, t.Minute, t.Second, t.NanoSecond)
}
}
func (t *Time) Deserialize(v string) error {
var h, m, s, ns string
split1 := strings.Split(v, ".")
if len(split1) == 2 {
split2 := strings.Split(split1[0], ":")
if len(split2) == 3 {
h = split2[0]
m = split2[1]
s = split2[2]
ns = split1[1]
} else {
return fmt.Errorf("invalid time format: %s", v)
}
} else if len(split1) == 1 {
split2 := strings.Split(split1[0], ":")
if len(split2) == 2 {
h = split2[0]
m = split2[1]
s = "0"
ns = "0"
} else if len(split2) == 3 {
h = split2[0]
m = split2[1]
s = split2[2]
ns = "0"
} else {
return fmt.Errorf("invalid time format: %s", v)
}
} else {
return fmt.Errorf("invalid time format: %s", v)
}
ns = langext.StrPadRight(ns, "0", 9)
hh, err := strconv.ParseInt(h, 10, 32)
if err != nil {
return fmt.Errorf("invalid time format: %s", v)
}
mm, err := strconv.ParseInt(m, 10, 32)
if err != nil {
return fmt.Errorf("invalid time format: %s", v)
}
ss, err := strconv.ParseInt(s, 10, 32)
if err != nil {
return fmt.Errorf("invalid time format: %s", v)
}
nss, err := strconv.ParseInt(ns, 10, 32)
if err != nil {
return fmt.Errorf("invalid time format: %s", v)
}
t.Hour = int(hh)
t.Minute = int(mm)
t.Second = int(ss)
t.NanoSecond = int(nss)
return nil
}
func (t Time) FormatStr() string {
return "15:04:05.999999999"
}
func (t Time) GoString() string {
return fmt.Sprintf("rfctime.NewTime(%d, %d, %d, %d)", t.Hour, t.Minute, t.Second, t.NanoSecond)
}
func (t Time) String() string {
return fmt.Sprintf("%04d:%02d:%02d.%09d", t.Hour, t.Minute, t.Second, t.NanoSecond)
}
func NewTime(h int, m int, s int, ns int) Time {
return Time{
Hour: h,
Minute: m,
Second: s,
NanoSecond: ns,
}
}
func NewTimeFromTS(t time.Time) Time {
return Time{
Hour: t.Hour(),
Minute: t.Minute(),
Second: t.Second(),
NanoSecond: t.Nanosecond(),
}
}
func NowTime(loc *time.Location) Time {
now := time.Now().In(loc)
return NewTime(now.Hour(), now.Minute(), now.Second(), now.Nanosecond())
}
func NowTimeLoc() Time {
return NowTime(time.UTC)
}
func NowTimeUTC() Time {
return NowTime(time.Local)
}

View File

@@ -7,7 +7,10 @@ import (
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/rfctime"
"gogs.mikescher.com/BlackForestBytes/goext/timeext"
"reflect"
"strconv"
"strings"
"time"
)
@@ -78,6 +81,46 @@ var ConverterRFC339NanoTimeToString = NewDBTypeConverter[rfctime.RFC3339NanoTime
return rfctime.NewRFC3339Nano(t), nil
})
var ConverterRFCDateToString = NewDBTypeConverter[rfctime.Date, string](func(v rfctime.Date) (string, error) {
return fmt.Sprintf("%04d-%02d-%02d", v.Year, v.Month, v.Day), nil
}, func(v string) (rfctime.Date, error) {
split := strings.Split(v, "-")
if len(split) != 3 {
return rfctime.Date{}, errors.New("invalid date format: " + v)
}
year, err := strconv.ParseInt(split[0], 10, 32)
if err != nil {
return rfctime.Date{}, errors.New("invalid date format: " + v + ": " + err.Error())
}
month, err := strconv.ParseInt(split[0], 10, 32)
if err != nil {
return rfctime.Date{}, errors.New("invalid date format: " + v + ": " + err.Error())
}
day, err := strconv.ParseInt(split[0], 10, 32)
if err != nil {
return rfctime.Date{}, errors.New("invalid date format: " + v + ": " + err.Error())
}
return rfctime.Date{Year: int(year), Month: int(month), Day: int(day)}, nil
})
var ConverterRFCTimeToString = NewDBTypeConverter[rfctime.Time, string](func(v rfctime.Time) (string, error) {
return v.SerializeShort(), nil
}, func(v string) (rfctime.Time, error) {
res := rfctime.Time{}
err := res.Deserialize(v)
if err != nil {
return rfctime.Time{}, err
}
return res, nil
})
var ConverterRFCSecondsF64ToString = NewDBTypeConverter[rfctime.SecondsF64, float64](func(v rfctime.SecondsF64) (float64, error) {
return v.Seconds(), nil
}, func(v float64) (rfctime.SecondsF64, error) {
return rfctime.NewSecondsF64(timeext.FromSeconds(v)), nil
})
var ConverterJsonObjToString = NewDBTypeConverter[JsonObj, string](func(v JsonObj) (string, error) {
mrsh, err := json.Marshal(v)
if err != nil {

View File

@@ -143,14 +143,21 @@ func (db *database) RegisterConverter(conv DBTypeConverter) {
func (db *database) RegisterDefaultConverter() {
db.RegisterConverter(ConverterBoolToBit)
db.RegisterConverter(ConverterTimeToUnixMillis)
db.RegisterConverter(ConverterRFCUnixMilliTimeToUnixMillis)
db.RegisterConverter(ConverterRFCUnixNanoTimeToUnixNanos)
db.RegisterConverter(ConverterRFCUnixTimeToUnixSeconds)
db.RegisterConverter(ConverterRFC339TimeToString)
db.RegisterConverter(ConverterRFC339NanoTimeToString)
db.RegisterConverter(ConverterRFCDateToString)
db.RegisterConverter(ConverterRFCTimeToString)
db.RegisterConverter(ConverterRFCSecondsF64ToString)
db.RegisterConverter(ConverterJsonObjToString)
db.RegisterConverter(ConverterJsonArrToString)
db.RegisterConverter(ConverterExErrCategoryToString)
db.RegisterConverter(ConverterExErrSeverityToString)
db.RegisterConverter(ConverterExErrTypeToString)

View File

@@ -38,6 +38,13 @@ type fullTypeRef struct {
Index []int
}
type IColl interface {
Collection() *mongo.Collection
Name() string
Indexes() mongo.IndexView
Drop(ctx context.Context) error
}
type Coll[TData any] struct {
coll *mongo.Collection // internal mongo collection, access via Collection()
dataTypeMap map[string]fullTypeRef // list of TData fields (only if TData is not an interface)