mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-23 09:50:27 +08:00
test
This commit is contained in:
parent
1e1fc188b4
commit
ef0b9a9ebe
@ -39,38 +39,3 @@ 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,8 +32,7 @@ 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) {
|
||||||
|
@ -64,10 +64,13 @@ func rpcClientInterceptor(ctx context.Context, method string, req, reply interfa
|
|||||||
if ok {
|
if ok {
|
||||||
md.Append(constant.OpUserID, opUserID)
|
md.Append(constant.OpUserID, opUserID)
|
||||||
}
|
}
|
||||||
|
log.Info("", "rpc come here")
|
||||||
err = invoker(metadata.NewOutgoingContext(ctx, md), method, req, reply, cc, opts...)
|
err = invoker(metadata.NewOutgoingContext(ctx, md), method, req, reply, cc, opts...)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
log.Info("", "rpc come here err")
|
||||||
|
|
||||||
rpcErr, ok := err.(interface{ GRPCStatus() *status.Status })
|
rpcErr, ok := err.(interface{ GRPCStatus() *status.Status })
|
||||||
if !ok {
|
if !ok {
|
||||||
return errs.NewCodeError(errs.DefaultOtherError, err.Error()).Wrap()
|
return errs.NewCodeError(errs.DefaultOtherError, err.Error()).Wrap()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user