22 lines
335 B
Go
22 lines
335 B
Go
package ws_handler
|
|
|
|
import "encoding/json"
|
|
|
|
type msg struct {
|
|
Type string `json:"type"`
|
|
Data string `json:"data"`
|
|
}
|
|
|
|
func parseMsg(data []byte) (*msg, error) {
|
|
m := &msg{}
|
|
if err := json.Unmarshal(data, m); err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func wapMsg(m *msg) []byte {
|
|
data, _ := json.Marshal(m)
|
|
return data
|
|
}
|