24 lines
510 B
Go
24 lines
510 B
Go
package main
|
|
|
|
import (
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
type Actions struct {
|
|
Functions map[string]func(ws *websocket.Conn, msg []byte) error
|
|
}
|
|
|
|
func (actions Actions) add(name string, callback func(ws *websocket.Conn, msg []byte) error) {
|
|
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 {
|
|
return actions.Functions[name](ws, msg)
|
|
}
|