reid 2 rokov pred
rodič
commit
f40ab7bdc9
5 zmenil súbory, kde vykonal 52 pridanie a 53 odobranie
  1. 35 35
      broadcast/broadcast.go
  2. 4 4
      config/config.go
  3. 3 4
      docker/docker.go
  4. 7 7
      startram/startram.go
  5. 3 3
      structs/structs.go

+ 35 - 35
broadcast/broadcast.go

@@ -7,9 +7,9 @@ import (
 	"goseg/docker"
 	"goseg/startram"
 	"goseg/structs"
+	"io/ioutil"
 	"log/slog"
 	"math"
-	"io/ioutil"
 	"os"
 	"path/filepath"
 	"reflect"
@@ -93,7 +93,7 @@ func bootstrapBroadcastState(config structs.SysConfig) (structs.AuthBroadcast, e
 					},
 				},
 			},
-		}		
+		}
 		err := UpdateBroadcastState(updates)
 		if err != nil {
 			errmsg := fmt.Sprintf("Error updating broadcast state:", err)
@@ -180,7 +180,7 @@ func GetContainerNetworks(containers []string) map[string]string {
 	for _, container := range containers {
 		network, err := docker.GetContainerNetwork(container)
 		if err != nil {
-			errmsg := fmt.Sprintf("Error getting container network: %v",err)
+			errmsg := fmt.Sprintf("Error getting container network: %v", err)
 			logger.Error(errmsg)
 			continue
 		} else {
@@ -207,17 +207,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())
@@ -241,33 +241,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

+ 4 - 4
config/config.go

@@ -31,8 +31,8 @@ var (
 	WifiNetworks       []string
 	HttpOpen           = false
 	UploadSecret       string
-	checkInterval	   = 5 * time.Minute
-	stagingMode		   = os.Getenv("ENVIRONMENT")
+	checkInterval      = 5 * time.Minute
+	stagingMode        = os.Getenv("ENVIRONMENT")
 	confMutex          sync.Mutex
 	versMutex          sync.Mutex
 )
@@ -50,7 +50,7 @@ func init() {
 			BasePath = "/opt/nativeplanet/groundseg"
 		}
 	}
-	pathMsg := fmt.Sprintf("Loading configs from %s",BasePath)
+	pathMsg := fmt.Sprintf("Loading configs from %s", BasePath)
 	logger.Info(pathMsg)
 	confPath := filepath.Join(BasePath, "settings", "system.json")
 	file, err := os.Open(confPath)
@@ -278,4 +278,4 @@ func CheckVersionLoop() {
 			}
 		}
 	}
-}
+}

+ 3 - 4
docker/docker.go

@@ -2,10 +2,10 @@ package docker
 
 import (
 	"context"
+	"encoding/json"
 	"fmt"
-	"log/slog"
 	"goseg/structs"
-	"encoding/json"
+	"log/slog"
 	"os"
 
 	"github.com/docker/docker/api/types"
@@ -54,7 +54,6 @@ func GetShipStatus(patps []string) (map[string]string, error) {
 	}
 }
 
-
 // return the name of a container's network
 func GetContainerNetwork(name string) (string, error) {
 	cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
@@ -102,4 +101,4 @@ func GetContainerStats(containerName string) (structs.ContainerStats, error) {
 		MemoryUsage: memUsage,
 		DiskUsage:   diskUsage,
 	}, nil
-}
+}

+ 7 - 7
startram/startram.go

@@ -1,18 +1,18 @@
 package startram
 
 import (
-	"fmt"
 	"encoding/json"
-	"os"
-	"log/slog"
-	"io/ioutil"
-	"net/http"
+	"fmt"
 	"goseg/config"
 	"goseg/structs"
+	"io/ioutil"
+	"log/slog"
+	"net/http"
+	"os"
 )
 
 var (
-	logger  = slog.New(slog.NewJSONHandler(os.Stdout, nil))
+	logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
 )
 
 func GetRegions() (map[string]structs.StartramRegion, error) {
@@ -41,4 +41,4 @@ func GetRegions() (map[string]structs.StartramRegion, error) {
 		return regions, err
 	}
 	return regions, nil
-}
+}

+ 3 - 3
structs/structs.go

@@ -155,8 +155,8 @@ type Urbit struct {
 		Running          bool   `json:"running"`
 		URL              string `json:"url"`
 		UrbAlias         bool   `json:"urbAlias"`
-		MemUsage         uint64    `json:"memUsage"`
-		DiskUsage        int64    `json:"diskUsage"`
+		MemUsage         uint64 `json:"memUsage"`
+		DiskUsage        int64  `json:"diskUsage"`
 		LoomSize         int    `json:"loomSize"`
 		DevMode          bool   `json:"devMode"`
 		DetectBootStatus bool   `json:"detectBootStatus"`
@@ -257,4 +257,4 @@ type UrbitDocker struct {
 type ContainerStats struct {
 	MemoryUsage uint64
 	DiskUsage   int64
-}
+}