mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-26 19:46:57 +08:00
test
This commit is contained in:
parent
abc303d1b3
commit
768f1ce032
@ -39,3 +39,38 @@ func Call[A, B, C any](
|
|||||||
}
|
}
|
||||||
apiresp.GinSuccess(c, data) // 成功
|
apiresp.GinSuccess(c, data) // 成功
|
||||||
}
|
}
|
||||||
|
func Call2[A, B, C any](
|
||||||
|
_ func(client C, ctx context.Context, req *A, options ...grpc.CallOption) (*B, error),
|
||||||
|
client func() (C, error),
|
||||||
|
c *gin.Context,
|
||||||
|
) {
|
||||||
|
var req A
|
||||||
|
if err := c.BindJSON(&req); err != nil {
|
||||||
|
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error())) // 参数错误
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if check, ok := any(&req).(interface{ Check() error }); ok {
|
||||||
|
if err := check.Check(); err != nil {
|
||||||
|
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error())) // 参数校验失败
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cli, err := client()
|
||||||
|
if err != nil {
|
||||||
|
apiresp.GinError(c, errs.ErrInternalServer.Wrap(err.Error())) // 获取RPC连接失败
|
||||||
|
log.Error("0", "get rpc client conn err:", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if a, ok := any(&cli).(interface {
|
||||||
|
rpc(ctx context.Context, req *A, options ...grpc.CallOption) (*B, error)
|
||||||
|
}); ok {
|
||||||
|
data, err := a.rpc(c, &req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("0", "rpc call err:", err.Error())
|
||||||
|
apiresp.GinError(c, err) // RPC调用失败
|
||||||
|
return
|
||||||
|
}
|
||||||
|
apiresp.GinSuccess(c, data) // 成功
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -32,7 +32,8 @@ func (o *Auth) UserRegister(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *Auth) UserToken(c *gin.Context) {
|
func (o *Auth) UserToken(c *gin.Context) {
|
||||||
a2r.Call(auth.AuthClient.UserToken, o.client, c)
|
|
||||||
|
a2r.Call2(auth.AuthClient.UserToken, o.client, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Auth) ParseToken(c *gin.Context) {
|
func (o *Auth) ParseToken(c *gin.Context) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user