refactored deprecated code

This commit is contained in:
Stephan D
2026-03-03 22:29:03 +01:00
parent cd8e8071a9
commit ce5f90939f
14 changed files with 54 additions and 70 deletions

View File

@@ -10,6 +10,7 @@ import (
feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)
@@ -82,19 +83,33 @@ func dialGRPC(ctx context.Context, cfg clientConfig, address string) (*grpc.Clie
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
}
dialOpts := make([]grpc.DialOption, 0, 1)
if cfg.InsecureTransport {
return grpc.DialContext(
ctx,
address,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
)
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
}
return grpc.DialContext(
ctx,
address,
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
grpc.WithBlock(),
)
conn, err := grpc.NewClient(address, dialOpts...)
if err != nil {
return nil, err
}
conn.Connect()
if err := waitUntilReady(ctx, conn); err != nil {
_ = conn.Close()
return nil, err
}
return conn, nil
}
func waitUntilReady(ctx context.Context, conn *grpc.ClientConn) error {
for {
state := conn.GetState()
if state == connectivity.Ready {
return nil
}
if !conn.WaitForStateChange(ctx, state) {
return ctx.Err()
}
}
}