修复header匹配引错包的问题

This commit is contained in:
Liujian
2023-02-16 17:06:37 +08:00
parent 1842095b64
commit eb3ac1f95c
4 changed files with 20 additions and 13 deletions

View File

@@ -7,6 +7,8 @@ import (
"sync"
"time"
"github.com/google/uuid"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/peer"
@@ -66,13 +68,16 @@ func (c *Context) InsecureCertificateVerify(b bool) {
}
func NewContext(srv interface{}, stream grpc.ServerStream) *Context {
now := time.Now()
ctx, cancel := context.WithCancel(stream.Context())
var addr net.Addr = zeroTCPAddr
p, has := peer.FromContext(ctx)
if has {
addr = p.Addr
}
return &Context{
newCtx := &Context{
requestId: uuid.New().String(),
ctx: ctx,
cancel: cancel,
addr: addr,
@@ -84,6 +89,8 @@ func NewContext(srv interface{}, stream grpc.ServerStream) *Context {
labels: map[string]string{},
errChan: make(chan error),
}
newCtx.WithValue("request_time", now)
return newCtx
}
func (c *Context) RequestId() string {