Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhaominxu
Open-IM-Server
提交
70f50115
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,发现更多精彩内容 >>
提交
70f50115
编写于
5月 26, 2021
作者:
H
hailong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
push auth
上级
a7bedf1f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
136 addition
and
0 deletion
+136
-0
src/rpc/auth/Makefile
src/rpc/auth/Makefile
+26
-0
src/rpc/auth/auth/rpcAuth.go
src/rpc/auth/auth/rpcAuth.go
+61
-0
src/rpc/auth/auth/user_register.go
src/rpc/auth/auth/user_register.go
+20
-0
src/rpc/auth/auth/user_token.go
src/rpc/auth/auth/user_token.go
+29
-0
未找到文件。
src/rpc/auth/Makefile
0 → 100644
浏览文件 @
70f50115
.PHONY
:
all build run gotool install clean help
BINARY_NAME
=
open_im_auth
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/auth/auth/rpcAuth.go
0 → 100644
浏览文件 @
70f50115
package
rpcAuth
import
(
"Open_IM/src/common/config"
log2
"Open_IM/src/common/log"
pbAuth
"Open_IM/src/proto/auth"
"Open_IM/src/utils"
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
"google.golang.org/grpc"
"net"
"strconv"
"strings"
)
type
rpcAuth
struct
{
rpcPort
int
rpcRegisterName
string
etcdSchema
string
etcdAddr
[]
string
}
func
NewRpcAuthServer
(
port
int
)
*
rpcAuth
{
return
&
rpcAuth
{
rpcPort
:
port
,
rpcRegisterName
:
config
.
Config
.
RpcRegisterName
.
RpcGetTokenName
,
etcdSchema
:
config
.
Config
.
Etcd
.
EtcdSchema
,
etcdAddr
:
config
.
Config
.
Etcd
.
EtcdAddr
,
}
}
func
(
rpc
*
rpcAuth
)
Run
()
{
log2
.
Info
(
""
,
""
,
"rpc get_token init..."
)
address
:=
utils
.
ServerIP
+
":"
+
strconv
.
Itoa
(
rpc
.
rpcPort
)
listener
,
err
:=
net
.
Listen
(
"tcp"
,
address
)
if
err
!=
nil
{
log2
.
Error
(
""
,
""
,
"listen network failed, err = %s, address = %s"
,
err
.
Error
(),
address
)
return
}
log2
.
Info
(
""
,
""
,
"listen network success, address = %s"
,
address
)
//grpc server
srv
:=
grpc
.
NewServer
()
defer
srv
.
GracefulStop
()
//service registers with etcd
pbAuth
.
RegisterAuthServer
(
srv
,
rpc
)
err
=
getcdv3
.
RegisterEtcd
(
rpc
.
etcdSchema
,
strings
.
Join
(
rpc
.
etcdAddr
,
","
),
utils
.
ServerIP
,
rpc
.
rpcPort
,
rpc
.
rpcRegisterName
,
10
)
if
err
!=
nil
{
log2
.
Error
(
""
,
""
,
"register rpc get_token to etcd failed, err = %s"
,
err
.
Error
())
return
}
err
=
srv
.
Serve
(
listener
)
if
err
!=
nil
{
log2
.
Info
(
""
,
""
,
"rpc get_token fail, err = %s"
,
err
.
Error
())
return
}
log2
.
Info
(
""
,
""
,
"rpc get_token init success"
)
}
src/rpc/auth/auth/user_register.go
0 → 100644
浏览文件 @
70f50115
package
rpcAuth
import
(
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbAuth
"Open_IM/src/proto/auth"
"context"
)
func
(
rpc
*
rpcAuth
)
UserRegister
(
_
context
.
Context
,
pb
*
pbAuth
.
UserRegisterReq
)
(
*
pbAuth
.
UserRegisterResp
,
error
)
{
log
.
Info
(
""
,
""
,
"rpc user_register start, [data: %s]"
,
pb
.
String
())
if
err
:=
im_mysql_model
.
UserRegister
(
pb
);
err
!=
nil
{
log
.
Error
(
""
,
""
,
"rpc user_register error, [data: %s] [err: %s]"
,
pb
.
String
(),
err
.
Error
())
return
&
pbAuth
.
UserRegisterResp
{
Success
:
false
},
err
}
log
.
Info
(
""
,
""
,
"rpc user_register success return"
)
return
&
pbAuth
.
UserRegisterResp
{
Success
:
true
},
nil
}
src/rpc/auth/auth/user_token.go
0 → 100644
浏览文件 @
70f50115
package
rpcAuth
import
(
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/log"
pbAuth
"Open_IM/src/proto/auth"
"Open_IM/src/utils"
"context"
)
func
(
rpc
*
rpcAuth
)
UserToken
(
_
context
.
Context
,
pb
*
pbAuth
.
UserTokenReq
)
(
*
pbAuth
.
UserTokenResp
,
error
)
{
log
.
Info
(
""
,
""
,
"rpc user_token call start..., [pbTokenReq: %s]"
,
pb
.
String
())
_
,
err
:=
im_mysql_model
.
FindUserByUID
(
pb
.
UID
)
if
err
!=
nil
{
log
.
Error
(
""
,
""
,
"rpc user_token call..., im_mysql_model.AppServerFindFromUserByUserID fail [uid: %s] [err: %s]"
,
pb
.
UID
,
err
.
Error
())
return
&
pbAuth
.
UserTokenResp
{
ErrCode
:
500
,
ErrMsg
:
err
.
Error
()},
err
}
log
.
Info
(
""
,
""
,
"rpc user_token call..., im_mysql_model.AppServerFindFromUserByUserID"
)
tokens
,
expTime
,
err
:=
utils
.
CreateToken
(
pb
.
UID
,
""
,
pb
.
Platform
)
if
err
!=
nil
{
log
.
Error
(
""
,
""
,
"rpc user_token call..., utils.CreateToken fail [uid: %s] [err: %s]"
,
pb
.
UID
,
err
.
Error
())
return
&
pbAuth
.
UserTokenResp
{
ErrCode
:
500
,
ErrMsg
:
err
.
Error
()},
err
}
log
.
Info
(
""
,
""
,
"rpc user_token success return, [uid: %s] [tokens: %s]"
,
pb
.
UID
,
tokens
)
return
&
pbAuth
.
UserTokenResp
{
Token
:
tokens
,
ExpiredTime
:
expTime
},
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录