Add FileWorkspaceInfo

This commit is contained in:
George Suntres
2026-04-01 20:40:25 -04:00
parent 21fb60b7a9
commit e732870865
5 changed files with 77 additions and 5 deletions

View File

@@ -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)
}