From ccac2606b34865e5b369dc3aa2c94e6d425ee385 Mon Sep 17 00:00:00 2001 From: "Marcel M. Otte" Date: Wed, 3 Nov 2021 22:34:55 +0100 Subject: [PATCH] Some comments for own sake and some event handler stubs --- cmd/backive/main.go | 13 ++++++++++++- events/events.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/cmd/backive/main.go b/cmd/backive/main.go index 6a9fe0c..0039c4b 100644 --- a/cmd/backive/main.go +++ b/cmd/backive/main.go @@ -7,8 +7,19 @@ import ( ) func main() { + // TODO: do proper signal handling! fmt.Println("vim-go") - // load config + // find and load config config.Load() + // init scheduler and check for next needed runs? + + // start event loop + // accept event + // find associated device and it's backups + // mount device + // run backups, one after another if multiple + // unmount device + // end loop + } diff --git a/events/events.go b/events/events.go index b3adf69..3f1b829 100644 --- a/events/events.go +++ b/events/events.go @@ -1 +1,37 @@ package events + +import "net" + +var ls net.Listener +var done <-chan struct{} + +func Init(socketPath string) { + ls, err = net.Listen(socketPath) + if err != nil { + panic(err) + } +} + +func RunLoop() { + for { + go func() { + process() + }() + } + +} + +func process() { + client, err = ls.Accept() + if err != nil { + panic(err) + } + //TODO: rewrite to be safe regarding buffer length + buf := make([]byte, 2048) + nr, err := client.Read(buf) + if err != nil { + return + } + + data := buf[0:nr] +}