Przeglądaj źródła

add urbit status init to broadcast boostrap

reid 2 lat temu
rodzic
commit
ff0d9236d1
1 zmienionych plików z 12 dodań i 1 usunięć
  1. 12 1
      broadcast/broadcast.go

+ 12 - 1
broadcast/broadcast.go

@@ -111,7 +111,18 @@ func bootstrapBroadcastState(config structs.SysConfig) (structs.AuthBroadcast, e
 func UpdateBroadcastState(values map[string]interface{}) error {
     mu.Lock()
     defer mu.Unlock()
-    return recursiveUpdate(reflect.ValueOf(&broadcastState).Elem(), reflect.ValueOf(values))
+    v := reflect.ValueOf(&broadcastState).Elem()
+    for key, value := range values {
+        field := v.FieldByName(key)
+        if !field.IsValid() || !field.CanSet() {
+            return fmt.Errorf("field %s does not exist or is not settable", key)
+        }
+        if err := recursiveUpdate(field, reflect.ValueOf(value)); err != nil {
+            return err
+        }
+    }
+    BroadcastToClients()
+    return nil
 }
 
 // this allows us to insert stuff into nested vals and not overwrite the existing contents