remote-i3wm-go/actions.go

24 lines
510 B
Go
Raw Permalink Normal View History

2023-08-24 18:41:12 +02:00
package main
import (
"github.com/gorilla/websocket"
2023-08-24 18:41:12 +02:00
)
type Actions struct {
Functions map[string]func(ws *websocket.Conn, msg []byte) error
2023-08-24 18:41:12 +02:00
}
func (actions Actions) add(name string, callback func(ws *websocket.Conn, msg []byte) error) {
2023-08-24 18:41:12 +02:00
actions.Functions[name] = callback
}
func (actions Actions) has(name string) bool {
_, exists := actions.Functions[name]
return exists
}
func (actions Actions) exec(name string, ws *websocket.Conn, msg []byte) error {
2023-08-24 18:41:12 +02:00
return actions.Functions[name](ws, msg)
}