Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
68b06158b3 | |||
5f51173276
|
|||
1586314e3e
|
|||
254fe1556a
|
|||
52e74b59f5
|
@@ -10,49 +10,52 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// PubSub is a simple Pub/Sub Broker
|
||||
// Clients can subscribe to a namespace and receive published messages on this namespace
|
||||
// Messages are broadcast to all subscribers
|
||||
type PubSub[TNamespace comparable, TData any] struct {
|
||||
masterLock *sync.Mutex
|
||||
|
||||
subscriptions map[TNamespace][]*pubSubSubscription[TNamespace, TData]
|
||||
}
|
||||
|
||||
type PubSubSubscription interface {
|
||||
Unsubscribe()
|
||||
}
|
||||
|
||||
type pubSubSubscription[T any] struct {
|
||||
type pubSubSubscription[TNamespace comparable, TData any] struct {
|
||||
ID string
|
||||
|
||||
parent *PubSub[T]
|
||||
namespace string
|
||||
parent *PubSub[TNamespace, TData]
|
||||
namespace TNamespace
|
||||
|
||||
subLock *sync.Mutex
|
||||
|
||||
Func func(T)
|
||||
Chan chan T
|
||||
Func func(TData)
|
||||
Chan chan TData
|
||||
|
||||
UnsubChan chan bool
|
||||
}
|
||||
|
||||
func (p *pubSubSubscription[T]) Unsubscribe() {
|
||||
func (p *pubSubSubscription[TNamespace, TData]) Unsubscribe() {
|
||||
p.parent.unsubscribe(p)
|
||||
}
|
||||
|
||||
type PubSub[T any] struct {
|
||||
masterLock *sync.Mutex
|
||||
|
||||
subscriptions map[string][]*pubSubSubscription[T]
|
||||
}
|
||||
|
||||
func NewPubSub[T any](capacity int) *PubSub[T] {
|
||||
return &PubSub[T]{
|
||||
func NewPubSub[TNamespace comparable, TData any](capacity int) *PubSub[TNamespace, TData] {
|
||||
return &PubSub[TNamespace, TData]{
|
||||
masterLock: &sync.Mutex{},
|
||||
subscriptions: make(map[string][]*pubSubSubscription[T], capacity),
|
||||
subscriptions: make(map[TNamespace][]*pubSubSubscription[TNamespace, TData], capacity),
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *PubSub[T]) Namespaces() []string {
|
||||
func (ps *PubSub[TNamespace, TData]) Namespaces() []TNamespace {
|
||||
ps.masterLock.Lock()
|
||||
defer ps.masterLock.Unlock()
|
||||
|
||||
return langext.MapKeyArr(ps.subscriptions)
|
||||
}
|
||||
|
||||
func (ps *PubSub[T]) SubscriberCount(ns string) int {
|
||||
func (ps *PubSub[TNamespace, TData]) SubscriberCount(ns TNamespace) int {
|
||||
ps.masterLock.Lock()
|
||||
defer ps.masterLock.Unlock()
|
||||
|
||||
@@ -61,7 +64,7 @@ func (ps *PubSub[T]) SubscriberCount(ns string) int {
|
||||
|
||||
// Publish sends `data` to all subscriber
|
||||
// But unbuffered - if one is currently not listening, we skip (the actualReceiver < subscriber)
|
||||
func (ps *PubSub[T]) Publish(ns string, data T) (subscriber int, actualReceiver int) {
|
||||
func (ps *PubSub[TNamespace, TData]) Publish(ns TNamespace, data TData) (subscriber int, actualReceiver int) {
|
||||
ps.masterLock.Lock()
|
||||
subs := langext.ArrCopy(ps.subscriptions[ns])
|
||||
ps.masterLock.Unlock()
|
||||
@@ -91,7 +94,7 @@ func (ps *PubSub[T]) Publish(ns string, data T) (subscriber int, actualReceiver
|
||||
|
||||
// PublishWithContext sends `data` to all subscriber
|
||||
// buffered - if one is currently not listening, we wait (but error out when the context runs out)
|
||||
func (ps *PubSub[T]) PublishWithContext(ctx context.Context, ns string, data T) (subscriber int, actualReceiver int, err error) {
|
||||
func (ps *PubSub[TNamespace, TData]) PublishWithContext(ctx context.Context, ns TNamespace, data TData) (subscriber int, actualReceiver int, err error) {
|
||||
ps.masterLock.Lock()
|
||||
subs := langext.ArrCopy(ps.subscriptions[ns])
|
||||
ps.masterLock.Unlock()
|
||||
@@ -131,7 +134,7 @@ func (ps *PubSub[T]) PublishWithContext(ctx context.Context, ns string, data T)
|
||||
|
||||
// PublishWithTimeout sends `data` to all subscriber
|
||||
// buffered - if one is currently not listening, we wait (but wait at most `timeout` - if the timeout is exceeded then actualReceiver < subscriber)
|
||||
func (ps *PubSub[T]) PublishWithTimeout(ns string, data T, timeout time.Duration) (subscriber int, actualReceiver int) {
|
||||
func (ps *PubSub[TNamespace, TData]) PublishWithTimeout(ns TNamespace, data TData, timeout time.Duration) (subscriber int, actualReceiver int) {
|
||||
ps.masterLock.Lock()
|
||||
subs := langext.ArrCopy(ps.subscriptions[ns])
|
||||
ps.masterLock.Unlock()
|
||||
@@ -159,42 +162,42 @@ func (ps *PubSub[T]) PublishWithTimeout(ns string, data T, timeout time.Duration
|
||||
return subscriber, actualReceiver
|
||||
}
|
||||
|
||||
func (ps *PubSub[T]) SubscribeByCallback(ns string, fn func(T)) PubSubSubscription {
|
||||
func (ps *PubSub[TNamespace, TData]) SubscribeByCallback(ns TNamespace, fn func(TData)) PubSubSubscription {
|
||||
ps.masterLock.Lock()
|
||||
defer ps.masterLock.Unlock()
|
||||
|
||||
sub := &pubSubSubscription[T]{ID: xid.New().String(), namespace: ns, parent: ps, subLock: &sync.Mutex{}, Func: fn, UnsubChan: nil}
|
||||
sub := &pubSubSubscription[TNamespace, TData]{ID: xid.New().String(), namespace: ns, parent: ps, subLock: &sync.Mutex{}, Func: fn, UnsubChan: nil}
|
||||
|
||||
ps.subscriptions[ns] = append(ps.subscriptions[ns], sub)
|
||||
|
||||
return sub
|
||||
}
|
||||
|
||||
func (ps *PubSub[T]) SubscribeByChan(ns string, chanBufferSize int) (chan T, PubSubSubscription) {
|
||||
func (ps *PubSub[TNamespace, TData]) SubscribeByChan(ns TNamespace, chanBufferSize int) (chan TData, PubSubSubscription) {
|
||||
ps.masterLock.Lock()
|
||||
defer ps.masterLock.Unlock()
|
||||
|
||||
msgCh := make(chan T, chanBufferSize)
|
||||
msgCh := make(chan TData, chanBufferSize)
|
||||
|
||||
sub := &pubSubSubscription[T]{ID: xid.New().String(), namespace: ns, parent: ps, subLock: &sync.Mutex{}, Chan: msgCh, UnsubChan: nil}
|
||||
sub := &pubSubSubscription[TNamespace, TData]{ID: xid.New().String(), namespace: ns, parent: ps, subLock: &sync.Mutex{}, Chan: msgCh, UnsubChan: nil}
|
||||
|
||||
ps.subscriptions[ns] = append(ps.subscriptions[ns], sub)
|
||||
|
||||
return msgCh, sub
|
||||
}
|
||||
|
||||
func (ps *PubSub[T]) SubscribeByIter(ns string, chanBufferSize int) (iter.Seq[T], PubSubSubscription) {
|
||||
func (ps *PubSub[TNamespace, TData]) SubscribeByIter(ns TNamespace, chanBufferSize int) (iter.Seq[TData], PubSubSubscription) {
|
||||
ps.masterLock.Lock()
|
||||
defer ps.masterLock.Unlock()
|
||||
|
||||
msgCh := make(chan T, chanBufferSize)
|
||||
msgCh := make(chan TData, chanBufferSize)
|
||||
unsubChan := make(chan bool, 8)
|
||||
|
||||
sub := &pubSubSubscription[T]{ID: xid.New().String(), namespace: ns, parent: ps, subLock: &sync.Mutex{}, Chan: msgCh, UnsubChan: unsubChan}
|
||||
sub := &pubSubSubscription[TNamespace, TData]{ID: xid.New().String(), namespace: ns, parent: ps, subLock: &sync.Mutex{}, Chan: msgCh, UnsubChan: unsubChan}
|
||||
|
||||
ps.subscriptions[ns] = append(ps.subscriptions[ns], sub)
|
||||
|
||||
iterFun := func(yield func(T) bool) {
|
||||
iterFun := func(yield func(TData) bool) {
|
||||
for {
|
||||
select {
|
||||
case msg := <-msgCh:
|
||||
@@ -212,7 +215,7 @@ func (ps *PubSub[T]) SubscribeByIter(ns string, chanBufferSize int) (iter.Seq[T]
|
||||
return iterFun, sub
|
||||
}
|
||||
|
||||
func (ps *PubSub[T]) unsubscribe(p *pubSubSubscription[T]) {
|
||||
func (ps *PubSub[TNamespace, TData]) unsubscribe(p *pubSubSubscription[TNamespace, TData]) {
|
||||
ps.masterLock.Lock()
|
||||
defer ps.masterLock.Unlock()
|
||||
|
||||
@@ -229,7 +232,7 @@ func (ps *PubSub[T]) unsubscribe(p *pubSubSubscription[T]) {
|
||||
p.UnsubChan = nil
|
||||
}
|
||||
|
||||
ps.subscriptions[p.namespace] = langext.ArrFilter(ps.subscriptions[p.namespace], func(v *pubSubSubscription[T]) bool {
|
||||
ps.subscriptions[p.namespace] = langext.ArrFilter(ps.subscriptions[p.namespace], func(v *pubSubSubscription[TNamespace, TData]) bool {
|
||||
return v.ID != p.ID
|
||||
})
|
||||
if len(ps.subscriptions[p.namespace]) == 0 {
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestNewPubSub(t *testing.T) {
|
||||
ps := NewPubSub[string](10)
|
||||
ps := NewPubSub[string, string](10)
|
||||
if ps == nil {
|
||||
t.Fatal("NewPubSub returned nil")
|
||||
}
|
||||
@@ -21,7 +21,7 @@ func TestNewPubSub(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPubSub_Namespaces(t *testing.T) {
|
||||
ps := NewPubSub[string](10)
|
||||
ps := NewPubSub[string, string](10)
|
||||
|
||||
// Initially no namespaces
|
||||
namespaces := ps.Namespaces()
|
||||
@@ -60,7 +60,7 @@ func TestPubSub_Namespaces(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPubSub_SubscribeByCallback(t *testing.T) {
|
||||
ps := NewPubSub[string](10)
|
||||
ps := NewPubSub[string, string](10)
|
||||
|
||||
var received string
|
||||
var wg sync.WaitGroup
|
||||
@@ -94,7 +94,7 @@ func TestPubSub_SubscribeByCallback(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPubSub_SubscribeByChan(t *testing.T) {
|
||||
ps := NewPubSub[string](10)
|
||||
ps := NewPubSub[string, string](10)
|
||||
|
||||
ch, sub := ps.SubscribeByChan("test-ns", 1)
|
||||
defer sub.Unsubscribe()
|
||||
@@ -122,7 +122,7 @@ func TestPubSub_SubscribeByChan(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPubSub_SubscribeByIter(t *testing.T) {
|
||||
ps := NewPubSub[string](10)
|
||||
ps := NewPubSub[string, string](10)
|
||||
|
||||
iterSeq, sub := ps.SubscribeByIter("test-ns", 1)
|
||||
defer sub.Unsubscribe()
|
||||
@@ -165,7 +165,7 @@ func TestPubSub_SubscribeByIter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPubSub_Publish(t *testing.T) {
|
||||
ps := NewPubSub[string](10)
|
||||
ps := NewPubSub[string, string](10)
|
||||
|
||||
// Test publishing to a namespace with no subscribers
|
||||
subs, receivers := ps.Publish("empty-ns", "hello")
|
||||
@@ -215,7 +215,7 @@ func TestPubSub_Publish(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPubSub_PublishWithTimeout(t *testing.T) {
|
||||
ps := NewPubSub[string](10)
|
||||
ps := NewPubSub[string, string](10)
|
||||
|
||||
// Add a subscriber with a channel
|
||||
ch, sub := ps.SubscribeByChan("test-ns", 1)
|
||||
@@ -262,7 +262,7 @@ func TestPubSub_PublishWithTimeout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPubSub_PublishWithContext(t *testing.T) {
|
||||
ps := NewPubSub[string](10)
|
||||
ps := NewPubSub[string, string](10)
|
||||
|
||||
// Add a subscriber with a channel
|
||||
ch, sub := ps.SubscribeByChan("test-ns", 1)
|
||||
@@ -328,7 +328,7 @@ func TestPubSub_PublishWithContext(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPubSub_Unsubscribe(t *testing.T) {
|
||||
ps := NewPubSub[string](10)
|
||||
ps := NewPubSub[string, string](10)
|
||||
|
||||
// Add a subscriber
|
||||
ch, sub := ps.SubscribeByChan("test-ns", 1)
|
||||
@@ -372,7 +372,7 @@ func TestPubSub_Unsubscribe(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPubSub_MultipleSubscribers(t *testing.T) {
|
||||
ps := NewPubSub[string](10)
|
||||
ps := NewPubSub[string, string](10)
|
||||
|
||||
// Add multiple subscribers
|
||||
ch1, sub1 := ps.SubscribeByChan("test-ns", 1)
|
||||
|
@@ -5,17 +5,18 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/dataext"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/enums"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
//
|
||||
@@ -430,12 +431,22 @@ func (b *Builder) BuildAsExerr(ctxs ...context.Context) *ExErr {
|
||||
return FromError(b.wrappedErr)
|
||||
}
|
||||
|
||||
if pkgconfig.ZeroLogErrTraces && !b.noLog && (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Error())
|
||||
} else if pkgconfig.ZeroLogAllTraces && !b.noLog {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Error())
|
||||
}
|
||||
if pkgconfig.ZeroLogErrTraces && !b.noLog {
|
||||
if b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Error())
|
||||
} else if b.errorData.Severity == SevWarn {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Warn())
|
||||
} else if b.errorData.Severity == SevInfo {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Info())
|
||||
} else if b.errorData.Severity == SevDebug {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Debug())
|
||||
} else if b.errorData.Severity == SevTrace {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Trace())
|
||||
} else {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Error()) // ?!? unknown severity
|
||||
}
|
||||
|
||||
}
|
||||
b.errorData.CallListener(MethodBuild, ListenerOpt{NoLog: b.noLog})
|
||||
|
||||
return b.errorData
|
||||
@@ -456,10 +467,19 @@ func (b *Builder) Output(ctx context.Context, g *gin.Context) {
|
||||
|
||||
// this is only here to add one level to the trace
|
||||
// so that .Build() and .Output() and .Print() have the same depth and our stack-skip logger can have the same skip-count
|
||||
b.doOutput(ctx, g)
|
||||
b.doGinOutput(ctx, g)
|
||||
}
|
||||
|
||||
func (b *Builder) doOutput(ctx context.Context, g *gin.Context) {
|
||||
// OutputRaw works teh same as Output() - but does not depend on gin and works with a raw http.ResponseWriter
|
||||
func (b *Builder) OutputRaw(w http.ResponseWriter) {
|
||||
warnOnPkgConfigNotInitialized()
|
||||
|
||||
// this is only here to add one level to the trace
|
||||
// so that .Build() and .Output() and .Print() have the same depth and our stack-skip logger can have the same skip-count
|
||||
b.doRawOutput(w)
|
||||
}
|
||||
|
||||
func (b *Builder) doGinOutput(ctx context.Context, g *gin.Context) {
|
||||
b.errorData.Output(g)
|
||||
|
||||
if (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) && (pkgconfig.ZeroLogErrGinOutput || pkgconfig.ZeroLogAllGinOutput) {
|
||||
@@ -471,6 +491,18 @@ func (b *Builder) doOutput(ctx context.Context, g *gin.Context) {
|
||||
b.errorData.CallListener(MethodOutput, ListenerOpt{NoLog: b.noLog})
|
||||
}
|
||||
|
||||
func (b *Builder) doRawOutput(w http.ResponseWriter) {
|
||||
b.errorData.OutputRaw(w)
|
||||
|
||||
if (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) && (pkgconfig.ZeroLogErrGinOutput || pkgconfig.ZeroLogAllGinOutput) {
|
||||
b.errorData.Log(pkgconfig.ZeroLogger.Error())
|
||||
} else if (b.errorData.Severity == SevWarn) && (pkgconfig.ZeroLogAllGinOutput) {
|
||||
b.errorData.Log(pkgconfig.ZeroLogger.Warn())
|
||||
}
|
||||
|
||||
b.errorData.CallListener(MethodOutput, ListenerOpt{NoLog: b.noLog})
|
||||
}
|
||||
|
||||
// Print prints the error
|
||||
// If the error is SevErr we also send it to the error-service
|
||||
func (b *Builder) Print(ctxs ...context.Context) Proxy {
|
||||
@@ -492,8 +524,12 @@ func (b *Builder) doPrint() Proxy {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Warn())
|
||||
} else if b.errorData.Severity == SevInfo {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Info())
|
||||
} else {
|
||||
} else if b.errorData.Severity == SevDebug {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Debug())
|
||||
} else if b.errorData.Severity == SevTrace {
|
||||
b.errorData.ShortLog(pkgconfig.ZeroLogger.Trace())
|
||||
} else {
|
||||
b.errorData.Log(pkgconfig.ZeroLogger.Error()) // ?!? unknown severity
|
||||
}
|
||||
|
||||
b.errorData.CallListener(MethodPrint, ListenerOpt{NoLog: b.noLog})
|
||||
|
34
exerr/gin.go
34
exerr/gin.go
@@ -1,9 +1,9 @@
|
||||
package exerr
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
json "git.blackforestbytes.com/BlackForestBytes/goext/gojson"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
@@ -68,7 +68,6 @@ func (ee *ExErr) ToDefaultAPIJson() (string, error) {
|
||||
gjr := json.GoJsonRender{Data: ee.ToAPIJson(true, pkgconfig.ExtendedGinOutput, pkgconfig.IncludeMetaInGinOutput), NilSafeSlices: true, NilSafeMaps: true}
|
||||
|
||||
r, err := gjr.RenderString()
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -143,3 +142,34 @@ func (ee *ExErr) Output(g *gin.Context) {
|
||||
|
||||
g.Render(statuscode, json.GoJsonRender{Data: ginOutput, NilSafeSlices: true, NilSafeMaps: true})
|
||||
}
|
||||
|
||||
func (ee *ExErr) OutputRaw(w http.ResponseWriter) {
|
||||
|
||||
warnOnPkgConfigNotInitialized()
|
||||
|
||||
var statuscode = http.StatusInternalServerError
|
||||
|
||||
var baseCat = ee.RecursiveCategory()
|
||||
var baseType = ee.RecursiveType()
|
||||
var baseStatuscode = ee.RecursiveStatuscode()
|
||||
|
||||
if baseCat == CatUser {
|
||||
statuscode = http.StatusBadRequest
|
||||
} else if baseCat == CatSystem {
|
||||
statuscode = http.StatusInternalServerError
|
||||
}
|
||||
|
||||
if baseStatuscode != nil {
|
||||
statuscode = *ee.StatusCode
|
||||
} else if baseType.DefaultStatusCode != nil {
|
||||
statuscode = *baseType.DefaultStatusCode
|
||||
}
|
||||
|
||||
ginOutput, err := ee.ToDefaultAPIJson()
|
||||
if err != nil {
|
||||
panic(err) // cannot happen
|
||||
}
|
||||
|
||||
w.WriteHeader(statuscode)
|
||||
_, _ = w.Write([]byte(ginOutput))
|
||||
}
|
||||
|
22
go.mod
22
go.mod
@@ -11,25 +11,25 @@ require (
|
||||
github.com/rs/xid v1.6.0
|
||||
github.com/rs/zerolog v1.34.0
|
||||
go.mongodb.org/mongo-driver v1.17.4
|
||||
golang.org/x/crypto v0.40.0
|
||||
golang.org/x/sys v0.34.0
|
||||
golang.org/x/term v0.33.0
|
||||
golang.org/x/crypto v0.41.0
|
||||
golang.org/x/sys v0.35.0
|
||||
golang.org/x/term v0.34.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/jung-kurt/gofpdf v1.16.2
|
||||
golang.org/x/net v0.42.0
|
||||
golang.org/x/net v0.43.0
|
||||
golang.org/x/sync v0.16.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.13.3 // indirect
|
||||
github.com/bytedance/sonic v1.14.0 // indirect
|
||||
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||
github.com/cloudwego/base64x v0.1.6 // indirect
|
||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
|
||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
@@ -54,10 +54,10 @@ require (
|
||||
github.com/xdg-go/scram v1.1.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
||||
golang.org/x/arch v0.19.0 // indirect
|
||||
golang.org/x/image v0.29.0 // indirect
|
||||
golang.org/x/text v0.27.0 // indirect
|
||||
google.golang.org/protobuf v1.36.6 // indirect
|
||||
golang.org/x/arch v0.20.0 // indirect
|
||||
golang.org/x/image v0.30.0 // indirect
|
||||
golang.org/x/text v0.28.0 // indirect
|
||||
google.golang.org/protobuf v1.36.8 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
modernc.org/libc v1.37.6 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
|
24
go.sum
24
go.sum
@@ -23,6 +23,8 @@ github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqp
|
||||
github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
|
||||
github.com/bytedance/sonic v1.13.3 h1:MS8gmaH16Gtirygw7jV91pDCN33NyMrPbN7qiYhEsF0=
|
||||
github.com/bytedance/sonic v1.13.3/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
|
||||
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
|
||||
github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
|
||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM=
|
||||
github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
@@ -40,6 +42,8 @@ github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/
|
||||
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
||||
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
|
||||
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
||||
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
|
||||
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
|
||||
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
|
||||
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
@@ -60,6 +64,8 @@ github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3G
|
||||
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
||||
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
|
||||
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
|
||||
github.com/gabriel-vasile/mimetype v1.4.10 h1:zyueNbySn/z8mJZHLt6IPw0KoZsiQNszIpU+bX4+ZK0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.10/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=
|
||||
@@ -232,6 +238,8 @@ golang.org/x/arch v0.18.0 h1:WN9poc33zL4AzGxqf8VtpKUnGvMi8O9lhNyBMF/85qc=
|
||||
golang.org/x/arch v0.18.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
|
||||
golang.org/x/arch v0.19.0 h1:LmbDQUodHThXE+htjrnmVD73M//D9GTH6wFZjyDkjyU=
|
||||
golang.org/x/arch v0.19.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
|
||||
golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c=
|
||||
golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||
@@ -258,6 +266,8 @@ golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
|
||||
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
|
||||
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
|
||||
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
|
||||
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
|
||||
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
|
||||
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.21.0 h1:c5qV36ajHpdj4Qi0GnE0jUc/yuo33OLFaa0d+crTD5s=
|
||||
@@ -278,6 +288,8 @@ golang.org/x/image v0.28.0 h1:gdem5JW1OLS4FbkWgLO+7ZeFzYtL3xClb97GaUzYMFE=
|
||||
golang.org/x/image v0.28.0/go.mod h1:GUJYXtnGKEUgggyzh+Vxt+AviiCcyiwpsl8iQ8MvwGY=
|
||||
golang.org/x/image v0.29.0 h1:HcdsyR4Gsuys/Axh0rDEmlBmB68rW1U9BUdB3UVHsas=
|
||||
golang.org/x/image v0.29.0/go.mod h1:RVJROnf3SLK8d26OW91j4FrIHGbsJ8QnbEocVTOWQDA=
|
||||
golang.org/x/image v0.30.0 h1:jD5RhkmVAnjqaCUXfbGBrn3lpxbknfN9w2UhHHU+5B4=
|
||||
golang.org/x/image v0.30.0/go.mod h1:SAEUTxCCMWSrJcCy/4HwavEsfZZJlYxeHLc6tTiAe/c=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
@@ -306,6 +318,8 @@ golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
|
||||
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
|
||||
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
|
||||
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
|
||||
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
||||
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
@@ -353,6 +367,8 @@ golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
|
||||
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
|
||||
@@ -373,6 +389,8 @@ golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
|
||||
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
|
||||
golang.org/x/term v0.33.0 h1:NuFncQrRcaRvVmgRkvM3j/F00gWIAlcmlB8ACEKmGIg=
|
||||
golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0=
|
||||
golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4=
|
||||
golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
@@ -395,6 +413,8 @@ golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
||||
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
|
||||
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
|
||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
@@ -415,6 +435,10 @@ google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwl
|
||||
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||
google.golang.org/protobuf v1.36.7 h1:IgrO7UwFQGJdRNXH/sQux4R1Dj1WAKcLElzeeRaXV2A=
|
||||
google.golang.org/protobuf v1.36.7/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
|
||||
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
@@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.591"
|
||||
const GoextVersion = "0.0.596"
|
||||
|
||||
const GoextVersionTimestamp = "2025-07-16T12:44:55+0200"
|
||||
const GoextVersionTimestamp = "2025-08-26T15:55:57+0200"
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package langext
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type MapEntry[T comparable, V any] struct {
|
||||
Key T
|
||||
Value V
|
||||
@@ -72,6 +74,19 @@ func ForceMap[K comparable, V any](v map[K]V) map[K]V {
|
||||
}
|
||||
}
|
||||
|
||||
func ForceJsonMapOrPanic(v any) map[string]any {
|
||||
data, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var result map[string]any
|
||||
err = json.Unmarshal(data, &result)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
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)))
|
||||
|
||||
|
Reference in New Issue
Block a user