瀏覽代碼

load urbit config

nallux 2 年之前
父節點
當前提交
ca20545508
共有 2 個文件被更改,包括 70 次插入36 次删除
  1. 35 35
      broadcast/broadcast.go
  2. 35 1
      docker/urbit.go

+ 35 - 35
broadcast/broadcast.go

@@ -92,8 +92,8 @@ func bootstrapBroadcastState(config structs.SysConfig) (structs.AuthBroadcast, e
 	currentState = GetState()
 	// get startram regions
 	logger.Info("Retrieving StarTram region info")
-	wgRegistered := config.WgRegistered
-	wgOn := config.WgOn
+	//wgRegistered := config.WgRegistered
+	//wgOn := config.WgOn
 	regions, err := startram.GetRegions()
 	if err != nil {
 		logger.Warn("Couldn't get StarTram regions")
@@ -106,7 +106,7 @@ func bootstrapBroadcastState(config structs.SysConfig) (structs.AuthBroadcast, e
 					},
 				},
 			},
-		}		
+		}
 		err := UpdateBroadcastState(updates)
 		if err != nil {
 			errmsg := fmt.Sprintf("Error updating broadcast state:", err)
@@ -135,17 +135,17 @@ func UpdateBroadcastState(values map[string]interface{}) error {
 		if err := recursiveUpdate(field, val); err != nil {
 			return err
 		}
-	}	
+	}
 	BroadcastToClients()
 	return nil
 }
 
 // this allows us to insert stuff into nested structs/keys and not overwrite the existing contents
 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 {
 		for _, key := range src.MapKeys() {
 			dstField := dst.FieldByName(key.String())
@@ -169,33 +169,33 @@ func recursiveUpdate(dst, src reflect.Value) error {
 		}
 		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

+ 35 - 1
docker/urbit.go

@@ -1,9 +1,43 @@
 package docker
 
+import (
+	"fmt"
+	"goseg/config"
+	"sync"
+)
+
+var urbits = make(map[string]*sync.Mutex)
+
 func LoadUrbits() error {
 	logger.Info("Loading Urbit ships")
-	// load config from each pier
+	// Config struct
+	conf := config.Conf()
+	// Loop through pier list
+	for _, pier := range conf.Piers {
+		// load config
+		if err := loadConfig(pier); err != nil {
+			errmsg := fmt.Sprintf("Unable to load config for %s: %v", patp, err)
+			logger.Error(errmsg)
+		}
+	}
 	// apply latest version info (if automated updates)
 	// start containers
 	return nil
 }
+
+func loadConfig(pier string) error {
+	fmt.Println(pier)
+	/*
+		// try loading existing config
+		basePath, err := os.Getwd()
+		if err != nil {
+			errmsg := fmt.Sprintf("Couldn't get cwd: %v", err)
+			logger.Error(errmsg)
+		}
+		pierConf := fmt.Sprintf("%s.json", pier)
+		confPath := filepath.Join(basePath, "settings", "pier", pierConf)
+		file, err := os.Open(confPath)
+		defer file.Close()
+	*/
+	return nil
+}