This commit is contained in:
alex.sharov 2022-02-04 11:20:02 +07:00
parent 55080d5c01
commit d4b9053aed

View File

@ -13,9 +13,11 @@ import (
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery" grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/backoff" "google.golang.org/grpc/backoff"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive" "google.golang.org/grpc/keepalive"
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"
) )
func TLS(tlsCACert, tlsCertFile, tlsKeyFile string) (credentials.TransportCredentials, error) { func TLS(tlsCACert, tlsCertFile, tlsKeyFile string) (credentials.TransportCredentials, error) {
@ -112,3 +114,11 @@ func Connect(creds credentials.TransportCredentials, dialAddress string) (*grpc.
return grpc.DialContext(ctx, dialAddress, dialOpts...) return grpc.DialContext(ctx, dialAddress, dialOpts...)
} }
func IsRetryLater(err error) bool {
if s, ok := status.FromError(err); ok {
code := s.Code()
return code == codes.Unavailable || code == codes.Canceled || code == codes.ResourceExhausted
}
return false
}