99 "github.com/pubgo/funk/errors"
1010 "github.com/pubgo/funk/log"
1111 "github.com/pubgo/funk/recovery"
12- "github.com/pubgo/funk/result"
12+ "github.com/pubgo/funk/v2/ result"
1313 "github.com/pubgo/funk/vars"
1414 "github.com/pubgo/lava/clients/grpcc/grpcc_config"
1515 "github.com/pubgo/lava/core/metrics"
@@ -47,53 +47,53 @@ type clientImpl struct {
4747 middlewares []lava.Middleware
4848}
4949
50- func (t * clientImpl ) Invoke (ctx context.Context , method string , args , reply interface {} , opts ... grpc.CallOption ) (err error ) {
50+ func (t * clientImpl ) Invoke (ctx context.Context , method string , args , reply any , opts ... grpc.CallOption ) (err error ) {
5151 defer recovery .Err (& err , func (err error ) error {
5252 return errors .WrapTag (err , errors .T ("method" , method ), errors .T ("args" , args ))
5353 })
5454
5555 conn := t .Get ()
5656 if conn .IsErr () {
57- return errors .Wrapf (conn .Err (), "failed to get grpc client, service=%s, method=%s" , t .cfg .Service , method )
57+ return errors .Wrapf (conn .GetErr (), "failed to get grpc client, service=%s, method=%s" , t .cfg .Service , method )
5858 }
5959
60- return conn .Unwrap ().Invoke (ctx , method , args , reply , opts ... )
60+ return conn .Must ().Invoke (ctx , method , args , reply , opts ... )
6161}
6262
6363func (t * clientImpl ) Healthy (ctx context.Context ) error {
6464 conn := t .Get ()
6565 if conn .IsErr () {
66- return errors .Wrapf (conn .Err (), "failed to get grpc client, service=%s, method=healthy" , t .cfg .Service )
66+ return errors .Wrapf (conn .GetErr (), "failed to get grpc client, service=%s, method=healthy" , t .cfg .Service )
6767 }
6868
69- _ , err := grpc_health_v1 .NewHealthClient (conn .Unwrap ()).Check (ctx , & grpc_health_v1.HealthCheckRequest {})
69+ _ , err := grpc_health_v1 .NewHealthClient (conn .Must ()).Check (ctx , & grpc_health_v1.HealthCheckRequest {})
7070 return errors .Wrapf (err , "service %s heath check failed" , t .cfg .Service )
7171}
7272
7373func (t * clientImpl ) NewStream (ctx context.Context , desc * grpc.StreamDesc , method string , opts ... grpc.CallOption ) (grpc.ClientStream , error ) {
7474 conn := t .Get ()
7575 if conn .IsErr () {
76- return nil , errors .Wrapf (conn .Err (), "failed to get grpc client, service=%s, method=%s" , t .cfg .Service , method )
76+ return nil , errors .Wrapf (conn .GetErr (), "failed to get grpc client, service=%s, method=%s" , t .cfg .Service , method )
7777 }
7878
79- c , err1 := conn .Unwrap ().NewStream (ctx , desc , method , opts ... )
79+ c , err1 := conn .Must ().NewStream (ctx , desc , method , opts ... )
8080 return c , errors .Wrap (err1 , method )
8181}
8282
8383// Get new grpc client
8484func (t * clientImpl ) Get () (r result.Result [grpc.ClientConnInterface ]) {
85- defer recovery . Result (& r )
85+ defer result . RecoveryErr (& r )
8686
8787 if t .conn != nil {
88- return r .WithVal (t .conn )
88+ return r .WithValue (t .conn )
8989 }
9090
9191 t .mu .Lock ()
9292 defer t .mu .Unlock ()
9393
9494 // 双检, 避免多次创建
9595 if t .conn != nil {
96- return r .WithVal (t .conn )
96+ return r .WithValue (t .conn )
9797 }
9898
9999 conn , err := createConn (t .cfg , t .log , t .middlewares )
@@ -102,5 +102,5 @@ func (t *clientImpl) Get() (r result.Result[grpc.ClientConnInterface]) {
102102 }
103103
104104 t .conn = conn
105- return r .WithVal (t .conn )
105+ return r .WithValue (t .conn )
106106}
0 commit comments