simplegrpc

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AttrGRPCMethod is the simplerr attribute key for retrieving the grpc method
	AttrGRPCMethod = attr(1)
	// AttrGRPCStatus is the simplerr attribute key for retrieving the grpc Status object
	AttrGRPCStatus = attr(2)
)

Variables

This section is empty.

Functions

func DefaultInverseMapping added in v1.4.0

func DefaultInverseMapping() map[codes.Code]simplerr.Code

DefaultInverseMapping returns the default inverse mapping of gRPC error codes to SimpleError codes

func DefaultMapping

func DefaultMapping() map[simplerr.Code]codes.Code

DefaultMapping returns the default mapping of SimpleError codes to gRPC error codes

func ReturnSimpleErrors added in v1.4.0

func ReturnSimpleErrors(registry *Registry) grpc.UnaryClientInterceptor

ReturnSimpleErrors returns a unary client interceptor that converts errors returned by the client to simplerr compatible errors. The underlying grpc status and code can still be extracted using the same status.FromError() and status.Code() methods

func TranslateErrorCode

func TranslateErrorCode(registry *Registry) grpc.UnaryServerInterceptor

TranslateErrorCode inspects the error to see if it is a SimpleError. If it is, it attempts to translate the SimpleError code to the corresponding grpc error code. If no translation exists it returns a grpc error with Unknown error code.

Types

type Registry added in v1.4.0

type Registry struct {
	// contains filtered or unexported fields
}

Registry is a registry which contains the mapping between simplerr codes and grpc error codes

func GetDefaultRegistry added in v1.4.0

func GetDefaultRegistry() *Registry

GetDefaultRegistry returns the currently registered default registry used by this package.

func NewRegistry added in v1.4.0

func NewRegistry() *Registry

NewRegistry creates a new registry which contains the mapping to and from simplerr codes and grpc error codes

func (*Registry) SetInverseMapping added in v1.4.0

func (r *Registry) SetInverseMapping(m map[codes.Code]simplerr.Code)

SetInverseMapping sets the mapping from gRPC code to simplerr.Code

func (*Registry) SetMapping added in v1.4.0

func (r *Registry) SetMapping(m map[simplerr.Code]codes.Code)

SetMapping sets the mapping from simplerr.Code to gRPC code

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL