v0.0.428
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled

This commit is contained in:
2024-04-08 16:32:34 +02:00
parent 758e5a67b5
commit 8446b2da22
4 changed files with 55 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ package reflectext
import (
"encoding/json"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"reflect"
)
@@ -14,7 +15,16 @@ func ConvertStructToMap(v any, opts ...ConvertStructToMapOpt) any {
if len(opts) > 0 {
opt = opts[0]
}
return reflectToMap(reflect.ValueOf(v), opt)
res := reflectToMap(reflect.ValueOf(v), opt)
if v, ok := res.(map[string]any); ok {
return v
} else if langext.IsNil(res) {
return nil
} else {
panic("not an object")
}
}
func reflectToMap(fv reflect.Value, opt ConvertStructToMapOpt) any {