Compare commits

..

13 Commits
v3 ... master

Author SHA1 Message Date
4b926bb1bd fixup metadata
Some checks failed
build / test (push) Failing after 1m14s
build / lint (push) Successful in 9m18s
codeql / analyze (go) (push) Failing after 4s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-03-12 01:58:03 +03:00
a424fd9722 fixup logger field and metadata handling
Some checks failed
build / test (push) Failing after 56s
codeql / analyze (go) (push) Failing after 1m50s
build / lint (push) Successful in 9m19s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-03-11 23:52:29 +03:00
a3f79a7bed update go.mod
Some checks failed
build / test (push) Failing after 14m39s
codeql / analyze (go) (push) Failing after 3m16s
build / lint (push) Successful in 9m13s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-03-10 22:36:58 +03:00
72c01fe7c9 optimize
Some checks failed
build / test (push) Failing after 59s
codeql / analyze (go) (push) Failing after 1m41s
build / lint (push) Has been cancelled
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-03-10 22:28:34 +03:00
bd6ebc31d6 optimize
Some checks failed
build / test (push) Failing after 1m18s
codeql / analyze (go) (push) Failing after 2m24s
build / lint (push) Successful in 9m24s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-03-10 22:14:28 +03:00
9c5c08c188 update for latest micro
Some checks failed
build / test (push) Failing after 50s
build / lint (push) Successful in 39s
codeql / analyze (go) (push) Failing after 1m23s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-10-17 01:12:17 +03:00
6bb29d8d0e fix xid
Some checks failed
codeql / analyze (go) (push) Failing after 3m16s
build / test (push) Failing after 1m29s
build / lint (push) Failing after 2m35s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-08-24 12:29:47 +03:00
c069636bf3 Merge pull request 'fix server subscriber' (#103) from idfix into master
Some checks failed
build / test (push) Failing after 1m28s
build / lint (push) Failing after 2m40s
codeql / analyze (go) (push) Failing after 3m5s
Reviewed-on: #103
2023-08-24 09:32:34 +03:00
a34c33e25b fix server subscriber
Some checks failed
codeql / analyze (go) (pull_request) Failing after 3m17s
dependabot-automerge / automerge (pull_request) Has been skipped
prbuild / test (pull_request) Failing after 1m30s
prbuild / lint (pull_request) Failing after 2m34s
autoapprove / autoapprove (pull_request) Failing after 1m27s
automerge / automerge (pull_request) Failing after 4s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-08-24 09:26:45 +03:00
fdffd31ed3 Merge pull request 'insert request id in context' (#101) from rr into master
Some checks failed
build / test (push) Failing after 1m30s
build / lint (push) Failing after 2m34s
codeql / analyze (go) (push) Failing after 3m9s
Reviewed-on: #101
2023-08-23 16:34:27 +03:00
1a3daf4263 insert request id in context
Some checks failed
dependabot-automerge / automerge (pull_request) Has been skipped
prbuild / test (pull_request) Failing after 1m29s
prbuild / lint (pull_request) Failing after 2m38s
autoapprove / autoapprove (pull_request) Failing after 1m25s
automerge / automerge (pull_request) Failing after 4s
codeql / analyze (go) (pull_request) Failing after 3m12s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-08-23 16:34:04 +03:00
a7932622b2 Merge pull request 'move to micro v4' (#98) from v4 into master
Reviewed-on: #98
2023-05-07 19:41:34 +03:00
300d1fe705 move to micro v4
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-07 19:41:15 +03:00
5 changed files with 56 additions and 85 deletions

View File

@ -47,7 +47,7 @@ jobs:
- name: setup
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.20
# Initializes the CodeQL tools for scanning.
- name: init
uses: github/codeql-action/init@v2

11
go.mod
View File

@ -1,12 +1,5 @@
module go.unistack.org/micro-wrapper-requestid/v3
module go.unistack.org/micro-wrapper-requestid/v4
go 1.20
require go.unistack.org/micro/v3 v3.10.66
require (
golang.org/x/sys v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
require go.unistack.org/micro/v4 v4.0.17

15
go.sum
View File

@ -1,13 +1,2 @@
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
go.unistack.org/micro/v3 v3.10.66 h1:tiG8HnyTC71IZWSC2qT/DmLhJinZJL9qvw+4Fvpm3d4=
go.unistack.org/micro/v3 v3.10.66/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be h1:LG9vZxsWGOmUKieR8wPAUR3u3MpnYFQZROPIMaXh7/A=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
go.unistack.org/micro/v4 v4.0.17 h1:mF7uM+J4ILdG+1fcwzKYCwDlxhdbF/e1WnGzKKLnIXc=
go.unistack.org/micro/v4 v4.0.17/go.mod h1:ZDgU9931vm2l7X6RN/6UuwRIVp24GRdmQ7dKmegArk4=

View File

@ -1,15 +1,16 @@
package requestid // import "go.unistack.org/micro-wrapper-requestid/v3"
package requestid
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"
"go.unistack.org/micro/v4/client"
"go.unistack.org/micro/v4/logger"
"go.unistack.org/micro/v4/metadata"
"go.unistack.org/micro/v4/options"
"go.unistack.org/micro/v4/server"
"go.unistack.org/micro/v4/util/id"
)
func init() {
@ -24,7 +25,7 @@ func init() {
type XRequestIDKey struct{}
// DefaultMetadataKey contains metadata key
// DefaultMetadataKey contains metadata key x-request-id
var DefaultMetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id")
// DefaultMetadataFunc wil be used if user not provide own func to fill metadata
@ -81,71 +82,55 @@ var DefaultMetadataFunc = func(ctx context.Context) (context.Context, error) {
return ctx, nil
}
type hook struct{}
func NewHook() *hook {
return &hook{}
type wrapper struct {
client.Client
}
func (w *hook) ServerSubscriber(next server.FuncSubHandler) server.FuncSubHandler {
return func(ctx context.Context, msg server.Message) error {
var err error
if xid, ok := msg.Header()[DefaultMetadataKey]; ok {
ctx = context.WithValue(ctx, XRequestIDKey{}, xid)
func NewClientWrapper() client.Wrapper {
return func(c client.Client) client.Client {
handler := &wrapper{
Client: c,
}
if ctx, err = DefaultMetadataFunc(ctx); err != nil {
return err
}
return next(ctx, msg)
return handler
}
}
func (w *hook) ServerHandler(next server.FuncHandler) server.FuncHandler {
return func(ctx context.Context, req server.Request, rsp interface{}) error {
var err error
if ctx, err = DefaultMetadataFunc(ctx); err != nil {
return err
func NewClientCallWrapper() client.CallWrapper {
return func(fn client.CallFunc) client.CallFunc {
return func(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions) error {
var err error
if ctx, err = DefaultMetadataFunc(ctx); err != nil {
return err
}
return fn(ctx, addr, req, rsp, opts)
}
return next(ctx, req, rsp)
}
}
func (w *hook) ClientBatchPublish(next client.FuncBatchPublish) client.FuncBatchPublish {
return func(ctx context.Context, msgs []client.Message, opts ...client.PublishOption) error {
var err error
if ctx, err = DefaultMetadataFunc(ctx); err != nil {
return err
}
return next(ctx, msgs, opts...)
func (w *wrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...options.Option) error {
var err error
if ctx, err = DefaultMetadataFunc(ctx); err != nil {
return err
}
return w.Client.Call(ctx, req, rsp, opts...)
}
func (w *hook) ClientPublish(next client.FuncPublish) client.FuncPublish {
return func(ctx context.Context, msg client.Message, opts ...client.PublishOption) error {
var err error
if ctx, err = DefaultMetadataFunc(ctx); err != nil {
return err
}
return next(ctx, msg, opts...)
func (w *wrapper) Stream(ctx context.Context, req client.Request, opts ...options.Option) (client.Stream, error) {
var err error
if ctx, err = DefaultMetadataFunc(ctx); err != nil {
return nil, err
}
return w.Client.Stream(ctx, req, opts...)
}
func (w *hook) ClientCall(next client.FuncCall) client.FuncCall {
return func(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
var err error
if ctx, err = DefaultMetadataFunc(ctx); err != nil {
return err
func NewServerHandlerWrapper() server.HandlerWrapper {
return func(fn server.HandlerFunc) server.HandlerFunc {
return func(ctx context.Context, req server.Request, rsp interface{}) error {
var err error
if ctx, err = DefaultMetadataFunc(ctx); err != nil {
return err
}
return fn(ctx, req, rsp)
}
return next(ctx, req, rsp, opts...)
}
}
func (w *hook) ClientStream(next client.FuncStream) client.FuncStream {
return func(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) {
var err error
if ctx, err = DefaultMetadataFunc(ctx); err != nil {
return nil, err
}
return next(ctx, req, opts...)
}
}

View File

@ -4,30 +4,34 @@ import (
"context"
"testing"
"go.unistack.org/micro/v3/metadata"
"go.unistack.org/micro/v4/metadata"
)
func TestDefaultMetadataFunc(t *testing.T) {
ctx := context.TODO()
var err error
nctx, err := DefaultMetadataFunc(ctx)
ctx, err = DefaultMetadataFunc(ctx)
if err != nil {
t.Fatalf("%v", err)
}
imd, ok := metadata.FromIncomingContext(nctx)
imd, ok := metadata.FromIncomingContext(ctx)
if !ok {
t.Fatalf("md missing in incoming context")
}
omd, ok := metadata.FromOutgoingContext(nctx)
omd, ok := metadata.FromOutgoingContext(ctx)
if !ok {
t.Fatalf("md missing in outgoing context")
}
_, iok := imd.Get(DefaultMetadataKey)
_, ook := omd.Get(DefaultMetadataKey)
iv, iok := imd.Get(DefaultMetadataKey)
ov, ook := omd.Get(DefaultMetadataKey)
if !iok || !ook {
t.Fatalf("missing metadata key value")
}
if iv != ov {
t.Fatalf("invalid metadata key value")
}
}