Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
catmes
EasyIM
提交
3f4508f9
E
EasyIM
项目概览
catmes
/
EasyIM
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
EasyIM
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3f4508f9
编写于
2月 25, 2023
作者:
W
wuhanqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
UPDATE protobuf Msg. ADD string access_token
上级
13efb93b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
63 addition
and
69 deletion
+63
-69
README.md
README.md
+7
-0
model/msg.pb.go
model/msg.pb.go
+31
-21
model/response.go
model/response.go
+23
-0
protobuf/msg.proto
protobuf/msg.proto
+1
-0
server/handler/http.go
server/handler/http.go
+1
-1
server/handler/httpresponse.go
server/handler/httpresponse.go
+0
-46
server/user/user.go
server/user/user.go
+0
-1
未找到文件。
README.md
浏览文件 @
3f4508f9
...
...
@@ -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
)
文件
...
...
model/msg.pb.go
浏览文件 @
3f4508f9
...
...
@@ -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
,
0x
a1
,
0x03
,
0x0a
,
0x03
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x12
,
0x05
,
0x6d
,
0x6f
,
0x64
,
0x65
,
0x6c
,
0x22
,
0x
c4
,
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
(
...
...
model/response.go
浏览文件 @
3f4508f9
...
...
@@ -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
)
}
protobuf/msg.proto
浏览文件 @
3f4508f9
...
...
@@ -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
server/handler/http.go
浏览文件 @
3f4508f9
...
...
@@ -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"
))
//
}
server/handler/httpresponse.go
已删除
100644 → 0
浏览文件 @
13efb93b
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
,
}}
}
}
server/user/user.go
浏览文件 @
3f4508f9
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录