mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-14 05:56:00 +08:00
proto modify
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"OpenIM/pkg/common/constant"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -27,7 +28,7 @@ func CorsHandler() gin.HandlerFunc {
|
||||
|
||||
func GinParseOperationID(c *gin.Context) {
|
||||
if c.Request.Method == http.MethodPost {
|
||||
operationID := c.Request.Header.Get("operationID")
|
||||
operationID := c.Request.Header.Get(constant.OperationID)
|
||||
if operationID == "" {
|
||||
body, err := ioutil.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
@@ -50,9 +51,9 @@ func GinParseOperationID(c *gin.Context) {
|
||||
}
|
||||
c.Request.Body = ioutil.NopCloser(bytes.NewReader(body))
|
||||
operationID = req.OperationID
|
||||
c.Request.Header.Set("operationID", operationID)
|
||||
c.Request.Header.Set(constant.OperationID, operationID)
|
||||
}
|
||||
c.Set("operationID", operationID)
|
||||
c.Set(constant.OperationID, operationID)
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func RpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
|
||||
if !ok {
|
||||
return nil, status.New(codes.InvalidArgument, "missing metadata").Err()
|
||||
}
|
||||
if opts := md.Get("operationID"); len(opts) != 1 || opts[0] == "" {
|
||||
if opts := md.Get(constant.OperationID); len(opts) != 1 || opts[0] == "" {
|
||||
return nil, status.New(codes.InvalidArgument, "operationID error").Err()
|
||||
} else {
|
||||
operationID = opts[0]
|
||||
@@ -71,7 +71,7 @@ func RpcClientInterceptor(ctx context.Context, method string, req, reply interfa
|
||||
//if cc == nil {
|
||||
// return utils.Wrap(constant.ErrRpcConn, "")
|
||||
//}
|
||||
operationID, ok := ctx.Value("operationID").(string)
|
||||
operationID, ok := ctx.Value(constant.OperationID).(string)
|
||||
if !ok {
|
||||
return utils.Wrap(constant.ErrArgs, "ctx missing operationID")
|
||||
}
|
||||
@@ -79,6 +79,6 @@ func RpcClientInterceptor(ctx context.Context, method string, req, reply interfa
|
||||
if !ok {
|
||||
return utils.Wrap(constant.ErrArgs, "ctx missing opUserID")
|
||||
}
|
||||
md := metadata.Pairs("operationID", operationID, "opUserID", opUserID)
|
||||
md := metadata.Pairs(constant.OperationID, operationID, "opUserID", opUserID)
|
||||
return invoker(metadata.NewOutgoingContext(ctx, md), method, req, reply, cc, opts...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user