v0.0.596 force json map
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m42s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m42s
This commit is contained in:
@@ -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