完善服务器
This commit is contained in:
@@ -2,20 +2,29 @@ package ws_handler
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type msg struct {
|
||||
type tempMsg struct {
|
||||
Type string `json:"type"`
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
func parseMsg(data []byte) (*msg, error) {
|
||||
m := &msg{}
|
||||
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 *msg) []byte {
|
||||
func wapMsg(m *tempMsg) []byte {
|
||||
data, _ := json.Marshal(m)
|
||||
return data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user