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