-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added metadata middleware for child balancers
- Loading branch information
Roman Golov
committed
Nov 1, 2024
1 parent
17a901b
commit 7ab3bba
Showing
5 changed files
with
53 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package balancer | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta" | ||
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
type Shared struct { | ||
balancer ConnBalancer | ||
meta *meta.Meta | ||
} | ||
|
||
func WithMetadata(b ConnBalancer, m *meta.Meta) *Shared { | ||
return &Shared{balancer: b, meta: m} | ||
} | ||
|
||
func (s *Shared) Invoke(ctx context.Context, method string, args any, reply any, | ||
opts ...grpc.CallOption) error { | ||
metaCtx, err := s.meta.Context(ctx) | ||
if err != nil { | ||
return xerrors.WithStackTrace(err) | ||
} | ||
return s.balancer.Invoke(metaCtx, method, args, reply, opts...) | ||
|
||
} | ||
|
||
func (s *Shared) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, | ||
opts ...grpc.CallOption) (grpc.ClientStream, error) { | ||
metaCtx, err := s.meta.Context(ctx) | ||
if err != nil { | ||
return nil, xerrors.WithStackTrace(err) | ||
} | ||
return s.balancer.NewStream(metaCtx, desc, method, opts...) | ||
} | ||
|
||
func (s *Shared) Close(ctx context.Context) error { | ||
return s.balancer.Close(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters