func (c *Conn) WriteJsonFaceCode(b interface{}, faceCode int) { var rsp Respon //请求数据的ID if c != nil && c.Request != nil { rsp.Header.RequestId = c.Request.Header.RequestId rsp.Header.UserUid = c.Request.Header.UserUid rsp.Header.UserAddr = c.Request.Header.UserAddr } rsp.Header.FaceCode = faceCode rsp.Header.ResponsId = util.GetUUID() rsp.Header.ResponTime = time.Now().Unix() switch e := b.(type) { case *errcode.Error: rsp.Header.ErrMsg = e.Msg rsp.Header.ErrCode = e.Code case error: rsp.Header.ErrMsg = e.Error() rsp.Header.ErrCode = -1 default: rsp.Header.ErrCode = 0 rsp.Body = b } d, _ := json.Marshal(&rsp) d = util.ByteLen(d) //加入包推送信息 if c.Server != nil && c.Server.DPM != nil && rsp.Header.FaceCode != 520 && rsp.Header.FaceCode != 200 { c.Server.DPM.AddPkg(rsp.Header.ResponsId, c.Conn.RemoteAddr().String(), rsp.Header.UserUid, d) } c.Write(d) }
func (c *ClientServer) Handle(conn *Conn) { c.CS.DataChan <- util.ByteLen(conn.Request.Marshal()) }