|
@@ -7,9 +7,9 @@ import (
|
|
|
"goseg/docker"
|
|
"goseg/docker"
|
|
|
"goseg/startram"
|
|
"goseg/startram"
|
|
|
"goseg/structs"
|
|
"goseg/structs"
|
|
|
|
|
+ "io/ioutil"
|
|
|
"log/slog"
|
|
"log/slog"
|
|
|
"math"
|
|
"math"
|
|
|
- "io/ioutil"
|
|
|
|
|
"os"
|
|
"os"
|
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
"reflect"
|
|
"reflect"
|
|
@@ -93,7 +93,7 @@ func bootstrapBroadcastState(config structs.SysConfig) (structs.AuthBroadcast, e
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
err := UpdateBroadcastState(updates)
|
|
err := UpdateBroadcastState(updates)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
errmsg := fmt.Sprintf("Error updating broadcast state:", err)
|
|
errmsg := fmt.Sprintf("Error updating broadcast state:", err)
|
|
@@ -180,7 +180,7 @@ func GetContainerNetworks(containers []string) map[string]string {
|
|
|
for _, container := range containers {
|
|
for _, container := range containers {
|
|
|
network, err := docker.GetContainerNetwork(container)
|
|
network, err := docker.GetContainerNetwork(container)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- errmsg := fmt.Sprintf("Error getting container network: %v",err)
|
|
|
|
|
|
|
+ errmsg := fmt.Sprintf("Error getting container network: %v", err)
|
|
|
logger.Error(errmsg)
|
|
logger.Error(errmsg)
|
|
|
continue
|
|
continue
|
|
|
} else {
|
|
} else {
|
|
@@ -207,17 +207,17 @@ func UpdateBroadcastState(values map[string]interface{}) error {
|
|
|
if err := recursiveUpdate(field, val); err != nil {
|
|
if err := recursiveUpdate(field, val); err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
BroadcastToClients()
|
|
BroadcastToClients()
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// this allows us to insert stuff into nested structs/keys and not overwrite the existing contents
|
|
// this allows us to insert stuff into nested structs/keys and not overwrite the existing contents
|
|
|
func recursiveUpdate(dst, src reflect.Value) error {
|
|
func recursiveUpdate(dst, src reflect.Value) error {
|
|
|
- if !dst.CanSet() {
|
|
|
|
|
- return fmt.Errorf("field is not settable")
|
|
|
|
|
- }
|
|
|
|
|
- // If dst is a struct and src is a map, handle them field by field
|
|
|
|
|
|
|
+ if !dst.CanSet() {
|
|
|
|
|
+ return fmt.Errorf("field is not settable")
|
|
|
|
|
+ }
|
|
|
|
|
+ // If dst is a struct and src is a map, handle them field by field
|
|
|
if dst.Kind() == reflect.Struct && src.Kind() == reflect.Map {
|
|
if dst.Kind() == reflect.Struct && src.Kind() == reflect.Map {
|
|
|
for _, key := range src.MapKeys() {
|
|
for _, key := range src.MapKeys() {
|
|
|
dstField := dst.FieldByName(key.String())
|
|
dstField := dst.FieldByName(key.String())
|
|
@@ -241,33 +241,33 @@ func recursiveUpdate(dst, src reflect.Value) error {
|
|
|
}
|
|
}
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
- // If both dst and src are maps, handle them recursively
|
|
|
|
|
- if dst.Kind() == reflect.Map && src.Kind() == reflect.Map {
|
|
|
|
|
- for _, key := range src.MapKeys() {
|
|
|
|
|
- srcVal := src.MapIndex(key)
|
|
|
|
|
- // If the key doesn't exist in dst, initialize it
|
|
|
|
|
- dstVal := dst.MapIndex(key)
|
|
|
|
|
- if !dstVal.IsValid() {
|
|
|
|
|
- dstVal = reflect.New(dst.Type().Elem()).Elem()
|
|
|
|
|
- }
|
|
|
|
|
- // Recursive call to handle potential nested maps or structs
|
|
|
|
|
- if err := recursiveUpdate(dstVal, srcVal); err != nil {
|
|
|
|
|
- return err
|
|
|
|
|
- }
|
|
|
|
|
- // Initialize the map if it's nil
|
|
|
|
|
- if dst.IsNil() {
|
|
|
|
|
- dst.Set(reflect.MakeMap(dst.Type()))
|
|
|
|
|
- }
|
|
|
|
|
- dst.SetMapIndex(key, dstVal)
|
|
|
|
|
- }
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
- // For non-map or non-struct fields, or for direct updates
|
|
|
|
|
- if dst.Type() != src.Type() {
|
|
|
|
|
- return fmt.Errorf("type mismatch: expected %s, got %s", dst.Type(), src.Type())
|
|
|
|
|
- }
|
|
|
|
|
- dst.Set(src)
|
|
|
|
|
- return nil
|
|
|
|
|
|
|
+ // If both dst and src are maps, handle them recursively
|
|
|
|
|
+ if dst.Kind() == reflect.Map && src.Kind() == reflect.Map {
|
|
|
|
|
+ for _, key := range src.MapKeys() {
|
|
|
|
|
+ srcVal := src.MapIndex(key)
|
|
|
|
|
+ // If the key doesn't exist in dst, initialize it
|
|
|
|
|
+ dstVal := dst.MapIndex(key)
|
|
|
|
|
+ if !dstVal.IsValid() {
|
|
|
|
|
+ dstVal = reflect.New(dst.Type().Elem()).Elem()
|
|
|
|
|
+ }
|
|
|
|
|
+ // Recursive call to handle potential nested maps or structs
|
|
|
|
|
+ if err := recursiveUpdate(dstVal, srcVal); err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ // Initialize the map if it's nil
|
|
|
|
|
+ if dst.IsNil() {
|
|
|
|
|
+ dst.Set(reflect.MakeMap(dst.Type()))
|
|
|
|
|
+ }
|
|
|
|
|
+ dst.SetMapIndex(key, dstVal)
|
|
|
|
|
+ }
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ // For non-map or non-struct fields, or for direct updates
|
|
|
|
|
+ if dst.Type() != src.Type() {
|
|
|
|
|
+ return fmt.Errorf("type mismatch: expected %s, got %s", dst.Type(), src.Type())
|
|
|
|
|
+ }
|
|
|
|
|
+ dst.Set(src)
|
|
|
|
|
+ return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// return broadcast state
|
|
// return broadcast state
|