Skip to content

Commit

Permalink
feat: add client interceptor
Browse files Browse the repository at this point in the history
Signed-off-by: jyjiangkai <jyjiangkai@163.com>
  • Loading branch information
hwjiangkai committed Apr 19, 2023
1 parent 8a595e6 commit 2b871c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions golang/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func Connect(options *ClientOptions) (Client, error) {
return nil, errors.New("endpoint is required for client")
}
opts := []grpc.DialOption{
grpc.WithUnaryInterceptor(UnaryClientInterceptor()),
grpc.WithTransportCredentials(insecure.NewCredentials()),
}
if options.Token != "" {
Expand Down
16 changes: 16 additions & 0 deletions golang/interceptor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package vanus

import (
"context"

"google.golang.org/grpc"

"github.com/vanus-labs/vanus/pkg/errors"
)

func UnaryClientInterceptor() grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req interface{}, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
err := invoker(ctx, method, req, reply, cc, opts...)
return errors.UnwrapOrUnknown(err)
}
}

0 comments on commit 2b871c0

Please sign in to comment.