Пример #1
0
func (c *Connection) read() {
	for {
		msg, err := binhelper.ReadMsg(c.conn)
		if err != nil {
			panic(err)
		}
		var v interface{}
		err = json.Unmarshal(msg, &v)
		if err != nil {
			panic(err)
		}
		c.sendOnChans(v.(map[string]interface{}))
	}
}
Пример #2
0
func readAndDecode(c net.Conn) (map[string]interface{}, error) {
	b, err := binhelper.ReadMsg(c)
	if err != nil {
		return nil, err
	}
	var v interface{}
	err = json.Unmarshal(b, &v)
	if err != nil {
		return nil, err
	}
	ma, ok := v.(map[string]interface{})
	if !ok {
		return nil, fmt.Errorf("Msg is not a map.")
	}
	return ma, nil
}