Add JsonPrintError
This commit is contained in:
15
struct.go
15
struct.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user