提交 3f4508f9 编写于 作者: W wuhanqing

UPDATE protobuf Msg. ADD string access_token

上级 13efb93b
......@@ -27,6 +27,12 @@ go mod tidy
# 首次运行,添加初始化参数--init,初始化数据库
go run . --init
# 正常开发时调试运行
go run .
# 编译为二进制文件. 然后直接运行./easyim(easyim.exe)
go build .
```
客户端调试:
......@@ -63,6 +69,7 @@ IM数据通讯的长连接,支持数据传输 `json`, `protobuf` 两种格式
| msg_type | MsgType | 消息类型(MsgType枚举类型:0文本,1图片,2语音,3视频) |
| status | MsgStatus | 消息状态(MsgStatus枚举类型:0未发送,1已发送,2已送达,3已读取) |
| content | string | 消息内容,字符串类型 |
| access_token | string | 鉴权令牌,字符串类型。用户登录成功后获取|
请参看 [protobuf/msg.proto](https://github.com/iotames/easyim/blob/master/protobuf/msg.proto)文件
......
......@@ -176,14 +176,15 @@ type Msg struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Seq uint32 `protobuf:"varint,2,opt,name=seq,proto3" json:"seq,omitempty"`
FromUserId string `protobuf:"bytes,3,opt,name=from_user_id,json=fromUserId,proto3" json:"from_user_id,omitempty"`
ToUserId string `protobuf:"bytes,4,opt,name=to_user_id,json=toUserId,proto3" json:"to_user_id,omitempty"`
ChatType Msg_ChatType `protobuf:"varint,5,opt,name=chat_type,json=chatType,proto3,enum=model.Msg_ChatType" json:"chat_type,omitempty"`
MsgType Msg_MsgType `protobuf:"varint,6,opt,name=msg_type,json=msgType,proto3,enum=model.Msg_MsgType" json:"msg_type,omitempty"`
Status Msg_MsgStatus `protobuf:"varint,7,opt,name=status,proto3,enum=model.Msg_MsgStatus" json:"status,omitempty"`
Content string `protobuf:"bytes,8,opt,name=content,proto3" json:"content,omitempty"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Seq uint32 `protobuf:"varint,2,opt,name=seq,proto3" json:"seq,omitempty"`
FromUserId string `protobuf:"bytes,3,opt,name=from_user_id,json=fromUserId,proto3" json:"from_user_id,omitempty"`
ToUserId string `protobuf:"bytes,4,opt,name=to_user_id,json=toUserId,proto3" json:"to_user_id,omitempty"`
ChatType Msg_ChatType `protobuf:"varint,5,opt,name=chat_type,json=chatType,proto3,enum=model.Msg_ChatType" json:"chat_type,omitempty"`
MsgType Msg_MsgType `protobuf:"varint,6,opt,name=msg_type,json=msgType,proto3,enum=model.Msg_MsgType" json:"msg_type,omitempty"`
Status Msg_MsgStatus `protobuf:"varint,7,opt,name=status,proto3,enum=model.Msg_MsgStatus" json:"status,omitempty"`
Content string `protobuf:"bytes,8,opt,name=content,proto3" json:"content,omitempty"`
AccessToken string `protobuf:"bytes,9,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"`
}
func (x *Msg) Reset() {
......@@ -274,11 +275,18 @@ func (x *Msg) GetContent() string {
return ""
}
func (x *Msg) GetAccessToken() string {
if x != nil {
return x.AccessToken
}
return ""
}
var File_protobuf_msg_proto protoreflect.FileDescriptor
var file_protobuf_msg_proto_rawDesc = []byte{
0x0a, 0x12, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x6d, 0x73, 0x67, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x22, 0xa1, 0x03, 0x0a, 0x03,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x22, 0xc4, 0x03, 0x0a, 0x03,
0x4d, 0x73, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x71, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d,
0x52, 0x03, 0x73, 0x65, 0x71, 0x12, 0x20, 0x0a, 0x0c, 0x66, 0x72, 0x6f, 0x6d, 0x5f, 0x75, 0x73,
......@@ -295,18 +303,20 @@ var file_protobuf_msg_proto_rawDesc = []byte{
0x18, 0x07, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x4d,
0x73, 0x67, 0x2e, 0x4d, 0x73, 0x67, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74,
0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18,
0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x21,
0x0a, 0x08, 0x43, 0x68, 0x61, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x49,
0x4e, 0x47, 0x4c, 0x45, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x47, 0x52, 0x4f, 0x55, 0x50, 0x10,
0x01, 0x22, 0x34, 0x0a, 0x07, 0x4d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x12, 0x08, 0x0a, 0x04,
0x54, 0x45, 0x58, 0x54, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x49, 0x4d, 0x41, 0x47, 0x45, 0x10,
0x01, 0x12, 0x09, 0x0a, 0x05, 0x56, 0x4f, 0x49, 0x43, 0x45, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05,
0x56, 0x49, 0x44, 0x45, 0x4f, 0x10, 0x03, 0x22, 0x36, 0x0a, 0x09, 0x4d, 0x73, 0x67, 0x53, 0x74,
0x61, 0x74, 0x75, 0x73, 0x12, 0x08, 0x0a, 0x04, 0x46, 0x41, 0x49, 0x4c, 0x10, 0x00, 0x12, 0x08,
0x0a, 0x04, 0x53, 0x45, 0x4e, 0x54, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x41, 0x52, 0x52, 0x49,
0x56, 0x45, 0x44, 0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x52, 0x45, 0x41, 0x44, 0x10, 0x03, 0x42,
0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x21,
0x0a, 0x0c, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x09,
0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65,
0x6e, 0x22, 0x21, 0x0a, 0x08, 0x43, 0x68, 0x61, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0a, 0x0a,
0x06, 0x53, 0x49, 0x4e, 0x47, 0x4c, 0x45, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x47, 0x52, 0x4f,
0x55, 0x50, 0x10, 0x01, 0x22, 0x34, 0x0a, 0x07, 0x4d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x12,
0x08, 0x0a, 0x04, 0x54, 0x45, 0x58, 0x54, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x49, 0x4d, 0x41,
0x47, 0x45, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x56, 0x4f, 0x49, 0x43, 0x45, 0x10, 0x02, 0x12,
0x09, 0x0a, 0x05, 0x56, 0x49, 0x44, 0x45, 0x4f, 0x10, 0x03, 0x22, 0x36, 0x0a, 0x09, 0x4d, 0x73,
0x67, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x08, 0x0a, 0x04, 0x46, 0x41, 0x49, 0x4c, 0x10,
0x00, 0x12, 0x08, 0x0a, 0x04, 0x53, 0x45, 0x4e, 0x54, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x41,
0x52, 0x52, 0x49, 0x56, 0x45, 0x44, 0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x52, 0x45, 0x41, 0x44,
0x10, 0x03, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
......
......@@ -55,3 +55,26 @@ func (r Response) HttpHtml() []byte {
headerText := strings.Join(header, "\n")
return []byte(headerText + "\n\r\n" + string(r.body))
}
type JsonObject map[string]interface{}
type ResponseApiData struct {
Code int
Msg string
Data JsonObject
}
func ResponseApi(data JsonObject, msg string, code int) ResponseApiData {
return ResponseApiData{Data: data, Msg: msg, Code: code}
}
func ResponseOk(msg string) ResponseApiData {
return ResponseApi(JsonObject{}, msg, http.StatusOK)
}
func ResponseFail(msg string, code int) ResponseApiData {
return ResponseApi(JsonObject{}, msg, code)
}
func ResponseItems(items interface{}) ResponseApiData {
return ResponseApi(JsonObject{"Items": items}, "success", http.StatusOK)
}
......@@ -32,4 +32,5 @@ message Msg {
MsgType msg_type = 6;
MsgStatus status = 7;
string content = 8;
string access_token = 9;
}
\ No newline at end of file
......@@ -10,5 +10,5 @@ func HttpHandler(req *model.Request) error {
hreq := req.GetHttpRequest()
body := req.GetHttpBody()
fmt.Printf("\n--method(%s)--proto(%s)--Path(%+v)--Body(%s)-\n", hreq.Method, hreq.Proto, hreq.URL, string(body))
return req.ResponseJson(ResponseOk("hello response Json From struct")) //
return req.ResponseJson(model.ResponseOk("hello response Json From struct")) //
}
package handler
import (
"fmt"
)
type JsonObject map[string]interface{}
func Response(data interface{}, msg string, code int) interface{} {
return struct {
Code int
Msg string
Data interface{}
}{Msg: msg, Code: code, Data: data}
}
func ResponseOk(msg string) interface{} {
return struct {
Code int
Msg string
Data JsonObject
}{Msg: msg, Code: 200, Data: JsonObject{}}
}
func ResponseFail(msg string, code int) interface{} {
return struct {
Code int
Msg string
Data JsonObject
}{Msg: msg, Code: code, Data: JsonObject{}}
}
func ResponseItems(items interface{}) interface{} {
switch items.(type) {
case string:
return fmt.Sprintf(`{"Code":200,"Msg":"success","Data":{"Items":%s}}`, items)
default:
return struct {
Code int
Msg string
Data JsonObject
}{Msg: "success", Code: 200, Data: JsonObject{
"Items": items,
}}
}
}
......@@ -126,7 +126,6 @@ func (u *User) GetConnData() (data []byte, err error) {
logger := miniutils.GetLogger("")
if n == 0 {
// 客户端主动或意外断开连接
logger.Debug("---user.GetConnData---connect lost---")
u.ConnectLost()
if !u.IsClosed {
err = u.Close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册