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
|
go 1.16
|
||||||
|
|
||||||
require (
|
require github.com/unistack-org/micro/v3 v3.7.0
|
||||||
github.com/google/uuid v1.2.0
|
|
||||||
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.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 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
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/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 h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||||
|
20
requestid.go
20
requestid.go
@ -4,20 +4,17 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"github.com/unistack-org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"github.com/unistack-org/micro/v3/metadata"
|
||||||
"github.com/unistack-org/micro/v3/server"
|
"github.com/unistack-org/micro/v3/server"
|
||||||
|
"github.com/unistack-org/micro/v3/util/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// MetadataKey contains metadata key
|
||||||
// MetadataKey contains metadata key
|
var MetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id")
|
||||||
MetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id")
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
// MetadataFunc wil be used if user not provide own func to fill metadata
|
||||||
// MetadataFunc wil be used if user not provide own func to fill metadata
|
var MetadataFunc = func(ctx context.Context) (context.Context, error) {
|
||||||
MetadataFunc = func(ctx context.Context) (context.Context, error) {
|
|
||||||
md, ok := metadata.FromIncomingContext(ctx)
|
md, ok := metadata.FromIncomingContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
md = metadata.New(1)
|
md = metadata.New(1)
|
||||||
@ -25,15 +22,14 @@ var (
|
|||||||
if _, ok = md.Get(MetadataKey); ok {
|
if _, ok = md.Get(MetadataKey); ok {
|
||||||
return ctx, nil
|
return ctx, nil
|
||||||
}
|
}
|
||||||
id, err := uuid.NewRandom()
|
uid, err := id.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx, err
|
return ctx, err
|
||||||
}
|
}
|
||||||
md.Set(MetadataKey, id.String())
|
md.Set(MetadataKey, uid)
|
||||||
ctx = metadata.NewIncomingContext(ctx, md)
|
ctx = metadata.NewIncomingContext(ctx, md)
|
||||||
return ctx, nil
|
return ctx, nil
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
type wrapper struct {
|
type wrapper struct {
|
||||||
client.Client
|
client.Client
|
||||||
|
Loading…
Reference in New Issue
Block a user