Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
a9295bfabf | |||
12fa53d848
|
|||
d2bb362135
|
|||
9dd81f6bd5
|
@@ -493,11 +493,12 @@ func (b *Builder) Format(level LogPrintLevel) string {
|
|||||||
// If the error is SevErr we also send it to the error-service
|
// If the error is SevErr we also send it to the error-service
|
||||||
func (b *Builder) Fatal(ctxs ...context.Context) {
|
func (b *Builder) Fatal(ctxs ...context.Context) {
|
||||||
|
|
||||||
|
b.errorData.Severity = SevFatal
|
||||||
|
|
||||||
for _, dctx := range ctxs {
|
for _, dctx := range ctxs {
|
||||||
b.CtxData(MethodFatal, dctx)
|
b.CtxData(MethodFatal, dctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.errorData.Severity = SevFatal
|
|
||||||
b.errorData.Log(stackSkipLogger.WithLevel(zerolog.FatalLevel))
|
b.errorData.Log(stackSkipLogger.WithLevel(zerolog.FatalLevel))
|
||||||
|
|
||||||
b.errorData.CallListener(MethodFatal)
|
b.errorData.CallListener(MethodFatal)
|
||||||
|
@@ -56,7 +56,7 @@ func wrapExErr(e *ExErr, msg string, cat ErrorCategory, stacktraceskip int) *ExE
|
|||||||
UniqueID: newID(),
|
UniqueID: newID(),
|
||||||
Category: cat,
|
Category: cat,
|
||||||
Type: TypeWrap,
|
Type: TypeWrap,
|
||||||
Severity: SevErr,
|
Severity: e.Severity,
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
StatusCode: e.StatusCode,
|
StatusCode: e.StatusCode,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
|
@@ -84,6 +84,9 @@ func (ee *ExErr) FormatLog(lvl LogPrintLevel) string {
|
|||||||
if lvl == LogPrintShort {
|
if lvl == LogPrintShort {
|
||||||
|
|
||||||
msg := ee.Message
|
msg := ee.Message
|
||||||
|
if msg == "" {
|
||||||
|
msg = ee.RecursiveMessage()
|
||||||
|
}
|
||||||
if ee.OriginalError != nil && ee.OriginalError.Category == CatForeign {
|
if ee.OriginalError != nil && ee.OriginalError.Category == CatForeign {
|
||||||
msg = msg + " (" + strings.ReplaceAll(ee.OriginalError.Message, "\n", " ") + ")"
|
msg = msg + " (" + strings.ReplaceAll(ee.OriginalError.Message, "\n", " ") + ")"
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@@ -32,7 +32,7 @@ require (
|
|||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.20.0 // indirect
|
github.com/go-playground/validator/v10 v10.21.0 // indirect
|
||||||
github.com/goccy/go-json v0.10.3 // indirect
|
github.com/goccy/go-json v0.10.3 // indirect
|
||||||
github.com/golang/snappy v0.0.4 // indirect
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
github.com/google/uuid v1.5.0 // indirect
|
github.com/google/uuid v1.5.0 // indirect
|
||||||
|
2
go.sum
2
go.sum
@@ -79,6 +79,8 @@ github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn
|
|||||||
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||||
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
|
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
|
||||||
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||||
|
github.com/go-playground/validator/v10 v10.21.0 h1:4fZA11ovvtkdgaeev9RGWPgc1uj3H8W+rNYyH/ySBb0=
|
||||||
|
github.com/go-playground/validator/v10 v10.21.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 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.463"
|
const GoextVersion = "0.0.466"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2024-05-29T20:20:01+0200"
|
const GoextVersionTimestamp = "2024-06-03T13:48:30+0200"
|
||||||
|
@@ -474,6 +474,17 @@ func ArrAppend[T any](arr []T, add ...T) []T {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArrPrepend works similar to append(x, y, z) - but doe snot touch the old array and creates a new one
|
||||||
|
// Also - in contrast to ArrAppend - the add values are inserted at the start of the resulting array (in reverse order)
|
||||||
|
func ArrPrepend[T any](arr []T, add ...T) []T {
|
||||||
|
out := make([]T, len(arr)+len(add))
|
||||||
|
copy(out[len(add):], arr)
|
||||||
|
for i := 0; i < len(add); i++ {
|
||||||
|
out[len(add)-i-1] = add[i]
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
// ArrCopy does a shallow copy of the 'in' array
|
// ArrCopy does a shallow copy of the 'in' array
|
||||||
func ArrCopy[T any](in []T) []T {
|
func ArrCopy[T any](in []T) []T {
|
||||||
out := make([]T, len(in))
|
out := make([]T, len(in))
|
||||||
|
@@ -2,6 +2,7 @@ package langext
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"gogs.mikescher.com/BlackForestBytes/goext/tst"
|
"gogs.mikescher.com/BlackForestBytes/goext/tst"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,3 +11,13 @@ func TestJoinString(t *testing.T) {
|
|||||||
res := JoinString(ids, ",")
|
res := JoinString(ids, ",")
|
||||||
tst.AssertEqual(t, res, "1,2,3")
|
tst.AssertEqual(t, res, "1,2,3")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestArrPrepend(t *testing.T) {
|
||||||
|
v1 := []string{"1", "2", "3"}
|
||||||
|
|
||||||
|
v2 := ArrPrepend(v1, "4", "5", "6")
|
||||||
|
|
||||||
|
tst.AssertEqual(t, strings.Join(v1, ""), "123")
|
||||||
|
tst.AssertEqual(t, strings.Join(v2, ""), "654123")
|
||||||
|
|
||||||
|
}
|
||||||
|
@@ -77,6 +77,14 @@ func Coalesce4Opt[T any](v1 *T, v2 *T, v3 *T, v4 *T) *T {
|
|||||||
return v4
|
return v4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CoalesceDblPtr[T any](v1 **T, v2 *T) *T {
|
||||||
|
if v1 != nil {
|
||||||
|
return *v1
|
||||||
|
}
|
||||||
|
|
||||||
|
return v2
|
||||||
|
}
|
||||||
|
|
||||||
func CoalesceString(s *string, def string) string {
|
func CoalesceString(s *string, def string) string {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return def
|
return def
|
||||||
|
Reference in New Issue
Block a user