Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhaominxu
Open-IM-Server
提交
e654e765
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,发现更多精彩内容 >>
提交
e654e765
编写于
5月 26, 2021
作者:
落凡尘.
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
user api service initial commit
上级
86bcee51
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
132 addition
and
0 deletion
+132
-0
src/api/user/get_user_info.go
src/api/user/get_user_info.go
+73
-0
src/api/user/update_user_info.go
src/api/user/update_user_info.go
+59
-0
未找到文件。
src/api/user/get_user_info.go
0 → 100644
浏览文件 @
e654e765
package
user
import
(
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbUser
"Open_IM/src/proto/user"
"context"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type
userInfo
struct
{
UID
string
`json:"uid"`
Name
string
`json:"name"`
Icon
string
`json:"icon"`
Gender
int32
`json:"gender"`
Mobile
string
`json:"mobile"`
Birth
string
`json:"birth"`
Email
string
`json:"email"`
Ex
string
`json:"ex"`
}
func
GetUserInfo
(
c
*
gin
.
Context
)
{
log
.
InfoByKv
(
"api get userinfo init..."
,
""
)
etcdConn
:=
getcdv3
.
GetConn
(
config
.
Config
.
Etcd
.
EtcdSchema
,
strings
.
Join
(
config
.
Config
.
Etcd
.
EtcdAddr
,
","
),
config
.
Config
.
RpcRegisterName
.
OpenImUserName
)
client
:=
pbUser
.
NewUserClient
(
etcdConn
)
params
:=
paramsStruct
{}
if
err
:=
c
.
BindJSON
(
&
params
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"errCode"
:
400
,
"errMsg"
:
err
.
Error
()})
return
}
req
:=
&
pbUser
.
GetUserInfoReq
{
UserIDList
:
params
.
UIDList
,
OperationID
:
params
.
OperationID
,
Token
:
c
.
Request
.
Header
.
Get
(
"token"
),
}
log
.
InfoByKv
(
"api get user info is server"
,
c
.
PostForm
(
"OperationID"
),
c
.
Request
.
Header
.
Get
(
"token"
))
RpcResp
,
err
:=
client
.
GetUserInfo
(
context
.
Background
(),
req
)
if
err
!=
nil
{
log
.
Error
(
req
.
Token
,
req
.
OperationID
,
"err=%s,call get user info rpc server failed"
,
err
)
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"errorCode"
:
500
,
"errorMsg"
:
"call rpc server failed"
,
})
return
}
log
.
InfoByKv
(
"call get user info rpc server success"
,
params
.
OperationID
)
if
RpcResp
.
ErrorCode
==
0
{
userInfoList
:=
make
([]
userInfo
,
0
)
for
_
,
user
:=
range
RpcResp
.
Data
{
var
ui
userInfo
ui
.
UID
=
user
.
Uid
ui
.
Name
=
user
.
Name
ui
.
Icon
=
user
.
Icon
ui
.
Gender
=
user
.
Gender
ui
.
Mobile
=
user
.
Mobile
ui
.
Birth
=
user
.
Birth
ui
.
Email
=
user
.
Email
ui
.
Ex
=
user
.
Ex
userInfoList
=
append
(
userInfoList
,
ui
)
}
resp
:=
gin
.
H
{
"errCode"
:
RpcResp
.
ErrorCode
,
"errMsg"
:
RpcResp
.
ErrorMsg
,
"data"
:
userInfoList
}
c
.
JSON
(
http
.
StatusOK
,
resp
)
}
else
{
resp
:=
gin
.
H
{
"errCode"
:
RpcResp
.
ErrorCode
,
"errMsg"
:
RpcResp
.
ErrorMsg
}
c
.
JSON
(
http
.
StatusOK
,
resp
)
}
log
.
InfoByKv
(
"api get user info return success"
,
params
.
OperationID
,
"args=%s"
,
RpcResp
.
String
())
}
src/api/user/update_user_info.go
0 → 100644
浏览文件 @
e654e765
package
user
import
(
"Open_IM/src/common/config"
"Open_IM/src/common/log"
pbUser
"Open_IM/src/proto/user"
"context"
"github.com/gin-gonic/gin"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"net/http"
"strings"
)
type
paramsStruct
struct
{
OperationID
string
`json:"operationID" binding:"required"`
UIDList
[]
string
`json:"uidList"`
Platform
int32
`json:"platform"`
Name
string
`json:"name"`
Icon
string
`json:"icon"`
Gender
int32
`json:"gender"`
Mobile
string
`json:"mobile"`
Birth
string
`json:"birth"`
Email
string
`json:"email"`
Ex
string
`json:"ex"`
}
func
UpdateUserInfo
(
c
*
gin
.
Context
)
{
log
.
InfoByKv
(
"api update userinfo init..."
,
""
)
etcdConn
:=
getcdv3
.
GetConn
(
config
.
Config
.
Etcd
.
EtcdSchema
,
strings
.
Join
(
config
.
Config
.
Etcd
.
EtcdAddr
,
","
),
config
.
Config
.
RpcRegisterName
.
OpenImUserName
)
client
:=
pbUser
.
NewUserClient
(
etcdConn
)
params
:=
paramsStruct
{}
if
err
:=
c
.
BindJSON
(
&
params
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"errCode"
:
400
,
"errMsg"
:
err
.
Error
()})
return
}
req
:=
&
pbUser
.
UpdateUserInfoReq
{
OperationID
:
params
.
OperationID
,
Token
:
c
.
Request
.
Header
.
Get
(
"token"
),
Name
:
params
.
Name
,
Icon
:
params
.
Icon
,
Gender
:
params
.
Gender
,
Mobile
:
params
.
Mobile
,
Birth
:
params
.
Birth
,
Email
:
params
.
Email
,
Ex
:
params
.
Ex
,
}
log
.
InfoByKv
(
"api update user info is server"
,
req
.
OperationID
,
req
.
Token
)
RpcResp
,
err
:=
client
.
UpdateUserInfo
(
context
.
Background
(),
req
)
if
err
!=
nil
{
log
.
Error
(
req
.
Token
,
req
.
OperationID
,
"err=%s,call get user info rpc server failed"
,
err
)
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"errCode"
:
500
,
"errMsg"
:
"call rpc server failed"
})
return
}
log
.
InfoByKv
(
"call update user info rpc server success"
,
params
.
OperationID
)
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"errCode"
:
RpcResp
.
ErrorCode
,
"errMsg"
:
RpcResp
.
ErrorMsg
})
log
.
InfoByKv
(
"api update user info return success"
,
params
.
OperationID
,
"args=%s"
,
RpcResp
.
String
())
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录