feat: introduce cluster events

This commit is contained in:
2025-05-17 20:07:51 +02:00
parent de8af61ba7
commit e30f167766
13 changed files with 190 additions and 62 deletions

34
pkg/cluster/events.go Normal file
View File

@@ -0,0 +1,34 @@
package cluster
import (
"log"
"github.com/0x1d/rcond/pkg/network"
"github.com/0x1d/rcond/pkg/system"
)
func ClusterEventsMap() map[string]func([]byte) {
return map[string]func([]byte){
"printHostname": printHostname,
"restart": restart,
"shutdown": shutdown,
}
}
func restart(payload []byte) {
if err := system.Restart(); err != nil {
log.Printf("(ClusterEvent:restart) failed: %s", err)
}
}
func shutdown(payload []byte) {
if err := system.Shutdown(); err != nil {
log.Printf("(ClusterEvent:shutdown) failed: %s", err)
}
}
// just a sample function to test event functionality
func printHostname(payload []byte) {
hostname, _ := network.GetHostname()
log.Printf("(ClusterEvent:printHostname): %s", hostname)
}