Add JsonPrintError

This commit is contained in:
George Suntres
2026-04-14 11:29:05 -04:00
parent 2fccb814c3
commit c0bee95cf6
4 changed files with 105 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import (
"log"
"reflect"
"strings"
"bytes"
"encoding/json"
"github.com/go-viper/mapstructure/v2"
@@ -52,8 +53,11 @@ func StructMustToMap(data any) map[string]any {
return nil
}
dec := json.NewDecoder(bytes.NewReader(b))
dec.UseNumber()
var res map[string]any
err = json.Unmarshal(b, &res)
err = dec.Decode(&res)
if err != nil {
log.Printf("Failed to unmarshal %v", err)
@@ -219,6 +223,15 @@ func BsonAToSlice(m any) ([]map[string]any, error) {
return o.Items, nil
}
func MapFromString(s string) (map[string]any, error) {
var b map[string]any
if err := bson.Unmarshal([]byte(s), &b); err != nil {
return nil, err
}
return b, nil
}
// MapIsSubset given two map[string]any m1 and m2 will determine if m1 is a subset of m2.
// Only fields' name is evaluated not their values.
func MapIsSubset(subset, superset any) bool {