3 Commits

Author SHA1 Message Date
c31b73f937 Merge pull request 'removed add loggerContextAttr' (#105) from devstigneev/micro-wrapper-requestid:v3 into v3
Some checks failed
codeql / analyze (go) (push) Failing after 1m54s
build / test (push) Failing after 5m17s
build / lint (push) Successful in 9m35s
Reviewed-on: #105
2024-12-06 12:38:12 +03:00
aee2908ed1 removed add loggerContextAttr
Some checks failed
automerge / automerge (pull_request) Has been skipped
dependabot-automerge / automerge (pull_request) Has been skipped
autoapprove / autoapprove (pull_request) Successful in 7s
codeql / analyze (go) (pull_request) Has been cancelled
prbuild / test (pull_request) Has been cancelled
prbuild / lint (pull_request) Has been cancelled
2024-12-06 00:29:56 +03:00
f85cbcdca2 rework
Some checks failed
build / test (push) Failing after 1m16s
codeql / analyze (go) (push) Failing after 1m37s
build / lint (push) Successful in 9m16s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-04-23 22:32:49 +03:00
2 changed files with 16 additions and 15 deletions

12
.gitignore vendored
View File

@@ -1,3 +1,9 @@
# Develop tools
/.vscode/
/.idea/
.idea
.vscode
# Binaries for programs and plugins
*.exe
*.exe~
@@ -5,6 +11,12 @@
*.so
*.dylib
# Folders
_obj
_test
_build
.DS_Store
# Test binary, built with `go test -c`
*.test

View File

@@ -2,26 +2,13 @@ package requestid // import "go.unistack.org/micro-wrapper-requestid/v3"
import (
"context"
"net/textproto"
"strings"
"go.unistack.org/micro/v3/client"
"go.unistack.org/micro/v3/logger"
"go.unistack.org/micro/v3/metadata"
"go.unistack.org/micro/v3/server"
"go.unistack.org/micro/v3/util/id"
"net/textproto"
)
func init() {
requestIDLog := strings.ToLower(DefaultMetadataKey)
logger.DefaultContextAttrFuncs = append(logger.DefaultContextAttrFuncs, func(ctx context.Context) []interface{} {
if v, ok := ctx.Value(XRequestIDKey{}).(string); ok {
return []interface{}{requestIDLog, v}
}
return nil
})
}
type XRequestIDKey struct{}
// DefaultMetadataKey contains metadata key
@@ -83,7 +70,9 @@ var DefaultMetadataFunc = func(ctx context.Context) (context.Context, error) {
type hook struct{}
var Hook = &hook{}
func NewHook() *hook {
return &hook{}
}
func (w *hook) ServerSubscriber(next server.FuncSubHandler) server.FuncSubHandler {
return func(ctx context.Context, msg server.Message) error {