v0.0.596 force json map
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m42s

This commit is contained in:
2025-08-26 15:55:57 +02:00
parent 5f51173276
commit 68b06158b3
4 changed files with 23 additions and 4 deletions

View File

@@ -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)))