rpc custom header

This commit is contained in:
withchao
2023-03-22 10:11:18 +08:00
parent c0d72d91fb
commit 900858e4ea
4 changed files with 17 additions and 4 deletions
+5 -1
View File
@@ -24,14 +24,18 @@ func rpcClientInterceptor(ctx context.Context, method string, req, resp interfac
}
log.ZInfo(ctx, "rpc client req", "funcName", method, "req", rpcString(req))
md := metadata.Pairs()
if keys, _ := ctx.Value(constant.RpcMwCustom).([]string); len(keys) > 0 {
if keys, _ := ctx.Value(constant.RpcCustomHeader).([]string); len(keys) > 0 {
for _, key := range keys {
val, ok := ctx.Value(key).([]string)
if !ok {
return errs.ErrInternalServer.Wrap(fmt.Sprintf("ctx missing key %s", key))
}
if len(val) == 0 {
return errs.ErrInternalServer.Wrap(fmt.Sprintf("ctx key %s value is empty", key))
}
md.Set(key, val...)
}
md.Set(constant.RpcCustomHeader, keys...)
}
operationID, ok := ctx.Value(constant.OperationID).(string)
if !ok {