grpc

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package grpc attaches GRPC codes to the standard error codes. It also provides helpers for integrating with GRPC.

Note that not all GRPC codes are mapped right now: you are welcome to contribute more. Available mappings are documented here: https://cloud.google.com/apis/design/errors

The init functiom performs the mapping and is reproduced here:

SetCode(errcode.InternalCode, codes.Internal)
SetCode(errcode.InvalidInputCode, codes.InvalidArgument)
SetCode(errcode.NotFoundCode, codes.NotFound)
SetCode(errcode.StateCode, codes.FailedPrecondition)
SetCode(errcode.ForbiddenCode, codes.PermissionDenied)
SetCode(errcode.NotAuthenticatedCode, codes.Unauthenticated)
SetCode(errcode.AlreadyExistsCode, codes.AlreadyExists)
SetCode(errcode.OutOfRangeCode, codes.OutOfRange)
SetCode(errcode.UnimplementedCode, codes.Unimplemented)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCode

func GetCode(code errcode.Code) codes.Code

GetCode retrieves the GRPC code for a code or its first ancestor with a GRPC code. If none are specified, it defaults to Unkown (Code 2). The return of this is a GRPC codes package Code, not an errcode.Code

func SetCode

func SetCode(code errcode.Code, grpcCode codes.Code) errcode.Code

SetCode adds a GRPC code to the meta data of a code. The code can be retrieved with GRPCCode. Panic if the metadata is already set for the code. Returns itself.

func Status

func Status(code errcode.ErrorCode) *status.Status

Status creates a GRPC Status object from an ErrorCode. TODO: add more information in the details fields.

Types

type ErrorCodeStatus

type ErrorCodeStatus interface {
	errcode.ErrorCode
	StatusGRPC
}

ErrorCodeStatus is both an ErrorCode and a GRPC Status

func WrapAsGRPC

func WrapAsGRPC(code errcode.ErrorCode) ErrorCodeStatus

WrapAsGRPC constructs a value that responds as both an ErrorCode and as a GRPC status

type StatusGRPC

type StatusGRPC interface {
	GRPCStatus() *status.Status
}

StatusGRPC is the interface to a GRPC status code

Jump to

Keyboard shortcuts

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