Skip to content

Commit

Permalink
feat: support custom ctx key to pass in servicei inline
Browse files Browse the repository at this point in the history
  • Loading branch information
Duslia committed Feb 19, 2025
1 parent 8bde660 commit 14655b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/consts/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const (
)

const (
SERVICE_INLINE_RPCINFO_KEY = "SERVICE_INLINE_RPCINFO_KEY"
SERVICE_INLINE_SERVICE_NAME = "SERVICE_INLINE_SERVICE_NAME"
SERVICE_INLINE_DATA_KEY = "SERVICE_INLINE_DATA_KEY"
SERVICE_INLINE_RPCINFO_KEY = "SERVICE_INLINE_RPCINFO_KEY"
SERVICE_INLINE_SERVICE_NAME = "SERVICE_INLINE_SERVICE_NAME"
SERVICE_INLINE_DATA_KEY = "SERVICE_INLINE_DATA_KEY"
SERVICE_INLINE_CUSTOM_CTX_KEY = "SERVICE_INLINE_CUSTOM_CTX_KEY"
)
4 changes: 4 additions & 0 deletions server/service_inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ var invocationType = reflect.TypeOf(rpcinfo.NewServerInvocation()).Elem()

func constructServerCtxWithMetadata(cliCtx context.Context) (serverCtx context.Context) {
serverCtx = context.Background()
customVal := cliCtx.Value(consts.SERVICE_INLINE_CUSTOM_CTX_KEY)
if customVal != nil {
serverCtx = context.WithValue(serverCtx, consts.SERVICE_INLINE_CUSTOM_CTX_KEY, customVal)

Check failure on line 42 in server/service_inline.go

View workflow job for this annotation

GitHub Actions / golangci-lint

SA1029: should not use built-in type string as key for value; define your own type to avoid collisions (staticcheck)
}

Check warning on line 43 in server/service_inline.go

View check run for this annotation

Codecov / codecov/patch

server/service_inline.go#L42-L43

Added lines #L42 - L43 were not covered by tests
// metainfo
// forward transmission
kvs := make(map[string]string, 16)
Expand Down

0 comments on commit 14655b3

Please sign in to comment.