From e5e7f7326a03a22495dd68c4f93fb0336b3bb619 Mon Sep 17 00:00:00 2001 From: Marcel Otte Date: Fri, 7 Jan 2022 12:08:25 +0100 Subject: [PATCH] Introducing a better interface Goal is to distinguish between udev input only and a gui for notifications. --- cmd/backive_udev/main.go | 6 +++++- events.go | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/backive_udev/main.go b/cmd/backive_udev/main.go index f162ad6..76ba8e4 100644 --- a/cmd/backive_udev/main.go +++ b/cmd/backive_udev/main.go @@ -34,12 +34,16 @@ func main() { env[pair[0]] = pair[1] log.Println(e) } + message := map[string]interface{}{} + + message["request"] = "udev" + message["data"] = env c, err := net.Dial("unix", "/var/local/backive/backive.sock") if err != nil { log.Fatalln("Could not instantiate unix socket. Aborting") } - jsonstr, err := json.Marshal(env) + jsonstr, err := json.Marshal(message) if err != nil { log.Fatalln("Could not convert to json. Aborting") } diff --git a/events.go b/events.go index e15f795..b9e8430 100644 --- a/events.go +++ b/events.go @@ -65,8 +65,14 @@ func (eh *EventHandler) process() { } sdata := string(bytes.Trim(data, "\x00")) //log.Println(sdata) - env := map[string]string{} - errjson := json.Unmarshal([]byte(sdata), &env) + var message map[string]interface{} + errjson := json.Unmarshal([]byte(sdata), &message) + var env = map[string]string{} + if message["request"] == "udev" { + for k, v := range message["data"].(map[string]interface{}) { + env[k] = v.(string) + } + } if errjson != nil { log.Fatal(errjson) }