Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhaominxu
Open-IM-Server
提交
2c3d0ae0
O
Open-IM-Server
项目概览
zhaominxu
/
Open-IM-Server
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Open-IM-Server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2c3d0ae0
编写于
5月 26, 2021
作者:
落凡尘.
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
user rpc service initial commit
上级
62d57140
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
161 addition
and
0 deletion
+161
-0
src/rpc/user/Makefile
src/rpc/user/Makefile
+27
-0
src/rpc/user/open_im_user.go
src/rpc/user/open_im_user.go
+13
-0
src/rpc/user/user/get_user_info.go
src/rpc/user/user/get_user_info.go
+96
-0
src/rpc/user/user/update_user_info.go
src/rpc/user/user/update_user_info.go
+25
-0
未找到文件。
src/rpc/user/Makefile
0 → 100644
浏览文件 @
2c3d0ae0
.PHONY
:
all build run gotool install clean help
BINARY_NAME
=
open_im_user
BIN_DIR
=
../../../bin/
LAN_FILE
=
.go
GO_FILE
:=
${BINARY_NAME}${LAN_FILE}
all
:
gotool build
build
:
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
${BINARY_NAME}
${GO_FILE}
run
:
@
go run ./
gotool
:
go
fmt
./
go vet ./
install
:
make build
mv
${BINARY_NAME}
${BIN_DIR}
clean
:
@
if
[
-f
${BINARY_NAME}
]
;
then
rm
${BINARY_NAME}
;
fi
src/rpc/user/open_im_user.go
0 → 100644
浏览文件 @
2c3d0ae0
package
main
import
(
"Open_IM/src/rpc/user/user"
"flag"
)
func
main
()
{
rpcPort
:=
flag
.
Int
(
"port"
,
10100
,
"rpc listening port"
)
flag
.
Parse
()
rpcServer
:=
user
.
NewUserServer
(
*
rpcPort
)
rpcServer
.
Run
()
}
src/rpc/user/user/get_user_info.go
0 → 100644
浏览文件 @
2c3d0ae0
package
user
import
(
"Open_IM/src/common/config"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbUser
"Open_IM/src/proto/user"
"Open_IM/src/utils"
"context"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"google.golang.org/grpc"
"net"
"strconv"
"strings"
)
type
userServer
struct
{
rpcPort
int
rpcRegisterName
string
etcdSchema
string
etcdAddr
[]
string
}
func
NewUserServer
(
port
int
)
*
userServer
{
return
&
userServer
{
rpcPort
:
port
,
rpcRegisterName
:
config
.
Config
.
RpcRegisterName
.
OpenImUserName
,
etcdSchema
:
config
.
Config
.
Etcd
.
EtcdSchema
,
etcdAddr
:
config
.
Config
.
Etcd
.
EtcdAddr
,
}
}
func
(
s
*
userServer
)
Run
()
{
log
.
Info
(
""
,
""
,
"rpc user init...."
)
ip
:=
utils
.
ServerIP
registerAddress
:=
ip
+
":"
+
strconv
.
Itoa
(
s
.
rpcPort
)
//listener network
listener
,
err
:=
net
.
Listen
(
"tcp"
,
registerAddress
)
if
err
!=
nil
{
log
.
InfoByArgs
(
"listen network failed,err=%s"
,
err
.
Error
())
return
}
log
.
Info
(
""
,
""
,
"listen network success, address = %s"
,
registerAddress
)
defer
listener
.
Close
()
//grpc server
srv
:=
grpc
.
NewServer
()
defer
srv
.
GracefulStop
()
//Service registers with etcd
pbUser
.
RegisterUserServer
(
srv
,
s
)
err
=
getcdv3
.
RegisterEtcd
(
s
.
etcdSchema
,
strings
.
Join
(
s
.
etcdAddr
,
","
),
ip
,
s
.
rpcPort
,
s
.
rpcRegisterName
,
10
)
if
err
!=
nil
{
log
.
ErrorByArgs
(
"register rpc token to etcd failed,err=%s"
,
err
.
Error
())
return
}
err
=
srv
.
Serve
(
listener
)
if
err
!=
nil
{
log
.
ErrorByArgs
(
"listen token failed,err=%s"
,
err
.
Error
())
return
}
log
.
Info
(
""
,
""
,
"rpc token init success"
)
}
func
(
s
*
userServer
)
GetUserInfo
(
ctx
context
.
Context
,
req
*
pbUser
.
GetUserInfoReq
)
(
*
pbUser
.
GetUserInfoResp
,
error
)
{
log
.
InfoByKv
(
"rpc get_user_info is server"
,
req
.
OperationID
)
var
userInfoList
[]
*
pbUser
.
UserInfo
//Obtain user information according to userID
if
len
(
req
.
UserIDList
)
>
0
{
for
_
,
userID
:=
range
req
.
UserIDList
{
var
userInfo
pbUser
.
UserInfo
user
,
err
:=
im_mysql_model
.
FindUserByUID
(
userID
)
if
err
!=
nil
{
log
.
ErrorByKv
(
"search userinfo failed"
,
req
.
OperationID
,
"userID"
,
userID
,
"err=%s"
,
err
.
Error
())
continue
}
userInfo
.
Uid
=
user
.
UID
userInfo
.
Icon
=
user
.
Icon
userInfo
.
Name
=
user
.
Name
userInfo
.
Gender
=
user
.
Gender
userInfo
.
Mobile
=
user
.
Mobile
userInfo
.
Birth
=
user
.
Birth
userInfo
.
Email
=
user
.
Email
userInfo
.
Ex
=
user
.
Ex
userInfoList
=
append
(
userInfoList
,
&
userInfo
)
}
}
else
{
return
&
pbUser
.
GetUserInfoResp
{
ErrorCode
:
999
,
ErrorMsg
:
"uidList is nil"
},
nil
}
log
.
InfoByKv
(
"rpc get userInfo return success"
,
req
.
OperationID
,
"token"
,
req
.
Token
)
return
&
pbUser
.
GetUserInfoResp
{
ErrorCode
:
0
,
ErrorMsg
:
""
,
Data
:
userInfoList
,
},
nil
}
src/rpc/user/user/update_user_info.go
0 → 100644
浏览文件 @
2c3d0ae0
package
user
import
(
"Open_IM/src/common/config"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
log2
"Open_IM/src/common/log"
pbUser
"Open_IM/src/proto/user"
"Open_IM/src/utils"
"context"
)
func
(
s
*
userServer
)
UpdateUserInfo
(
ctx
context
.
Context
,
req
*
pbUser
.
UpdateUserInfoReq
)
(
*
pbUser
.
CommonResp
,
error
)
{
log2
.
Info
(
req
.
Token
,
req
.
OperationID
,
"rpc modify user is server,args=%s"
,
req
.
String
())
claims
,
err
:=
utils
.
ParseToken
(
req
.
Token
)
if
err
!=
nil
{
log2
.
Error
(
req
.
Token
,
req
.
OperationID
,
"err=%s,parse token failed"
,
err
.
Error
())
return
&
pbUser
.
CommonResp
{
ErrorCode
:
config
.
ErrParseToken
.
ErrCode
,
ErrorMsg
:
err
.
Error
()},
nil
}
err
=
im_mysql_model
.
UpDateUserInfo
(
claims
.
UID
,
req
.
Name
,
req
.
Icon
,
req
.
Mobile
,
req
.
Birth
,
req
.
Email
,
req
.
Ex
,
req
.
Gender
)
if
err
!=
nil
{
log2
.
Error
(
req
.
Token
,
req
.
OperationID
,
"update user some attribute failed,err=%s"
,
err
.
Error
())
return
&
pbUser
.
CommonResp
{
ErrorCode
:
config
.
ErrModifyUserInfo
.
ErrCode
,
ErrorMsg
:
config
.
ErrModifyUserInfo
.
ErrMsg
},
nil
}
return
&
pbUser
.
CommonResp
{},
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录