Skip to content

Commit 08d505f

Browse files
committed
feat: support custom ctx key to pass in servicei inline
1 parent c50055a commit 08d505f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pkg/consts/ctx.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const (
2323
)
2424

2525
const (
26-
SERVICE_INLINE_RPCINFO_KEY = "SERVICE_INLINE_RPCINFO_KEY"
27-
SERVICE_INLINE_SERVICE_NAME = "SERVICE_INLINE_SERVICE_NAME"
28-
SERVICE_INLINE_DATA_KEY = "SERVICE_INLINE_DATA_KEY"
26+
SERVICE_INLINE_RPCINFO_KEY = "SERVICE_INLINE_RPCINFO_KEY"
27+
SERVICE_INLINE_SERVICE_NAME = "SERVICE_INLINE_SERVICE_NAME"
28+
SERVICE_INLINE_DATA_KEY = "SERVICE_INLINE_DATA_KEY"
29+
SERVICE_INLINE_CUSTOM_CTX_KEY = "SERVICE_INLINE_CUSTOM_CTX_KEY"
2930
)

server/service_inline.go

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ var invocationType = reflect.TypeOf(rpcinfo.NewServerInvocation()).Elem()
3535

3636
func constructServerCtxWithMetadata(cliCtx context.Context) (serverCtx context.Context) {
3737
serverCtx = context.Background()
38+
customVal := cliCtx.Value(consts.SERVICE_INLINE_CUSTOM_CTX_KEY)
39+
if customVal != nil {
40+
serverCtx = context.WithValue(serverCtx, consts.SERVICE_INLINE_CUSTOM_CTX_KEY, customVal)
41+
}
3842
// metainfo
3943
// forward transmission
4044
kvs := make(map[string]string, 16)

0 commit comments

Comments
 (0)