Procházet zdrojové kódy

add docker event feed

reid před 2 roky
rodič
revize
e4cf5b91dd
3 změnil soubory, kde provedl 14 přidání a 2 odebrání
  1. 2 1
      docker/docker.go
  2. 7 1
      rectify/rectify.go
  3. 5 0
      structs/structs.go

+ 2 - 1
docker/docker.go

@@ -18,6 +18,7 @@ import (
 
 var (
 	logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
+	EventBus = make(chan structs.Event, 100)
 )
 
 func GetShipStatus(patps []string) (map[string]string, error) {
@@ -311,7 +312,7 @@ func DockerListener() {
 		select {
 		case event := <-messages:
 			// Convert the Docker event to our custom event and send it to the EventBus
-			EventBus <- Event{Type: event.Action, Data: event}
+			EventBus <- structs.Event{Type: event.Action, Data: event}
 		case err := <-errs:
 			logger.Error(fmt.Sprintf("Docker event error: %v", err))
 		}

+ 7 - 1
rectify/rectify.go

@@ -5,11 +5,17 @@ package rectify
 import (
 	"fmt"
 	"goseg/broadcast"
+	"goseg/docker"
+	"log/slog"
+)
+
+var (
+	logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
 )
 
 func HandleDockerEvents() {
 	for {
-		event := <-EventBus
+		event := <-docker.EventBus
 		switch event.Type {
 		case "container_stopped":
 			logger.Info(fmt.Sprintf("Docker event: container stopped"))

+ 5 - 0
structs/structs.go

@@ -9,6 +9,11 @@ type WsPayload struct {
 	Action string `json:"action"`
 }
 
+type Event struct {
+	Type string
+	Data interface{}
+}
+
 type SessionInfo struct {
 	Hash    string `json:"hash"`
 	Created string `json:"created"`