Add FileWorkspaceInfo
This commit is contained in:
23
struct.go
23
struct.go
@@ -4,11 +4,33 @@ import (
|
||||
"log"
|
||||
"reflect"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/go-viper/mapstructure/v2"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// StructMustTomap given any struct return the equivalent map[string]any or nil.
|
||||
// Will never throw.
|
||||
func StructMustToMap(data any) map[string]any {
|
||||
b, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
log.Printf("Failed marshal %v", err)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var res map[string]any
|
||||
err = json.Unmarshal(b, &res)
|
||||
if err != nil {
|
||||
log.Printf("Failed to unmarshal %v", err)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// StructSetValue will update the value of the given field of struct o.
|
||||
func StructSetValue(o any, field string, value any) {
|
||||
ref := reflect.ValueOf(o).Elem()
|
||||
@@ -30,7 +52,6 @@ func StructSetValue(o any, field string, value any) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func StructToStruct(source any, target any) {
|
||||
mapstructure.Decode(source, &target)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user