gitlab.com/ignitionrobotics/web/ign-go@v1.0.0-rc4/net/grpc.go (about)

     1  package net
     2  
     3  import (
     4  	"google.golang.org/grpc/codes"
     5  	"google.golang.org/grpc/status"
     6  )
     7  
     8  // GRPCCallOK processes a gRPC response error to verify that a gRPC call returned an OK status.
     9  // The actual contents of the error are ignored. Only the call status error is checked.
    10  func GRPCCallOK(err error) bool {
    11  	return status.Code(err) == codes.OK
    12  }
    13  
    14  // GRPCCallSuccessful processes a gRPC response error to verify that a gRPC call returned an OK or Unknown status.
    15  // The actual contents of the error are ignored. Only the call status error is checked.
    16  //
    17  // gRPC method implementations that return anything other than a *Status value as their error value (e.g. an error
    18  // generated with errors.New()) will have the value wrapped inside a *Status value and its error code set to Unknown.
    19  //
    20  // This function considers calls with statuses with unknown errors successful. In addition, if the error value is
    21  // not of type *Status, then the call is considered successful.
    22  func GRPCCallSuccessful(err error) bool {
    23  	code := status.Code(err)
    24  
    25  	return code == codes.OK || code == codes.Unknown
    26  }