remove uuid dep

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-09-06 18:21:01 +03:00
parent 0c2006bb5b
commit 0bcf86ade7
3 changed files with 19 additions and 28 deletions

5
go.mod
View File

@ -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
View File

@ -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=

View File

@ -4,20 +4,17 @@ 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) {
// 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)
@ -25,15 +22,14 @@ var (
if _, ok = md.Get(MetadataKey); ok {
return ctx, nil
}
id, err := uuid.NewRandom()
uid, err := id.New()
if err != nil {
return ctx, err
}
md.Set(MetadataKey, id.String())
md.Set(MetadataKey, uid)
ctx = metadata.NewIncomingContext(ctx, md)
return ctx, nil
}
)
}
type wrapper struct {
client.Client