remove uuid dep
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
0c2006bb5b
commit
0bcf86ade7
5
go.mod
5
go.mod
@ -2,7 +2,4 @@ module github.com/unistack-org/micro-wrapper-requestid/v3
|
||||
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.2.0
|
||||
github.com/unistack-org/micro/v3 v3.7.0
|
||||
)
|
||||
require github.com/unistack-org/micro/v3 v3.7.0
|
||||
|
2
go.sum
2
go.sum
@ -27,8 +27,6 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
|
||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||
|
40
requestid.go
40
requestid.go
@ -4,36 +4,32 @@ import (
|
||||
"context"
|
||||
"net/textproto"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
"github.com/unistack-org/micro/v3/util/id"
|
||||
)
|
||||
|
||||
var (
|
||||
// MetadataKey contains metadata key
|
||||
MetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id")
|
||||
)
|
||||
// MetadataKey contains metadata key
|
||||
var MetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id")
|
||||
|
||||
var (
|
||||
// MetadataFunc wil be used if user not provide own func to fill metadata
|
||||
MetadataFunc = func(ctx context.Context) (context.Context, error) {
|
||||
md, ok := metadata.FromIncomingContext(ctx)
|
||||
if !ok {
|
||||
md = metadata.New(1)
|
||||
}
|
||||
if _, ok = md.Get(MetadataKey); ok {
|
||||
return ctx, nil
|
||||
}
|
||||
id, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
md.Set(MetadataKey, id.String())
|
||||
ctx = metadata.NewIncomingContext(ctx, md)
|
||||
// MetadataFunc wil be used if user not provide own func to fill metadata
|
||||
var MetadataFunc = func(ctx context.Context) (context.Context, error) {
|
||||
md, ok := metadata.FromIncomingContext(ctx)
|
||||
if !ok {
|
||||
md = metadata.New(1)
|
||||
}
|
||||
if _, ok = md.Get(MetadataKey); ok {
|
||||
return ctx, nil
|
||||
}
|
||||
)
|
||||
uid, err := id.New()
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
md.Set(MetadataKey, uid)
|
||||
ctx = metadata.NewIncomingContext(ctx, md)
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
type wrapper struct {
|
||||
client.Client
|
||||
|
Loading…
Reference in New Issue
Block a user