初始化
This commit is contained in:
@@ -3,7 +3,7 @@ package grpcx
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"xiaoxin-plus/pkg/errorx"
|
||||
"errors"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
@@ -14,6 +14,8 @@ type GrpcReqHeader struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
// 请求头
|
||||
|
||||
// 客户端写入请求header
|
||||
// 注意事项
|
||||
func WriteHeader(ctx context.Context, headers ...GrpcReqHeader) context.Context {
|
||||
@@ -43,7 +45,7 @@ func readHeaderAll(ctx context.Context) (header []GrpcReqHeader, err error) {
|
||||
// 本地的方式
|
||||
md, ok = metadata.FromOutgoingContext(ctx)
|
||||
if !ok {
|
||||
err = errorx.New("metadata.FromIncomingContext error")
|
||||
err = errors.New("metadata.FromIncomingContext error")
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -62,7 +64,7 @@ func ReadHeader(ctx context.Context, keys ...string) (header []GrpcReqHeader, er
|
||||
// 本地的方式
|
||||
md, ok = metadata.FromOutgoingContext(ctx)
|
||||
if !ok {
|
||||
err = errorx.New("metadata.FromIncomingContext error")
|
||||
err = errors.New("metadata.FromIncomingContext error")
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -77,6 +79,8 @@ func ReadHeader(ctx context.Context, keys ...string) (header []GrpcReqHeader, er
|
||||
return
|
||||
}
|
||||
|
||||
// 响应头
|
||||
|
||||
type GrpcRespHeader struct{}
|
||||
|
||||
func ServerWriteRespHeader(ctx context.Context, header GrpcRespHeader) {
|
||||
|
||||
Reference in New Issue
Block a user