Skip to content

Commit 6742604

Browse files
committed
feat: support custom ctx key to pass in servicei inline
1 parent 3c0b00f commit 6742604

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pkg/consts/ctx.go

Lines changed: 4 additions & 3 deletions
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ var invocationType = reflect.TypeOf(rpcinfo.NewServerInvocation()).Elem()
3737

3838
func constructServerCtxWithMetadata(cliCtx context.Context) (serverCtx context.Context) {
3939
serverCtx = context.Background()
40+
customVal := cliCtx.Value(consts.SERVICE_INLINE_CUSTOM_CTX_KEY)
41+
if customVal != nil {
42+
serverCtx = context.WithValue(serverCtx, consts.SERVICE_INLINE_CUSTOM_CTX_KEY, customVal)
43+
}
4044
// metainfo
4145
// forward transmission
4246
kvs := make(map[string]string, 16)

0 commit comments

Comments
 (0)