31 lines
495 B
Go
31 lines
495 B
Go
package ws_handler
|
|
|
|
import "encoding/json"
|
|
|
|
type tempMsg struct {
|
|
Type string `json:"type"`
|
|
Data string `json:"data"`
|
|
}
|
|
|
|
type tempAction struct {
|
|
Action int `json:"action"`
|
|
Data string `json:"data"`
|
|
}
|
|
|
|
type tempActionMove struct {
|
|
Move int `json:"move"`
|
|
}
|
|
|
|
func parseMsg(data []byte) (*tempMsg, error) {
|
|
m := &tempMsg{}
|
|
if err := json.Unmarshal(data, m); err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func wapMsg(m *tempMsg) []byte {
|
|
data, _ := json.Marshal(m)
|
|
return data
|
|
}
|