errors

package
v0.0.0-...-01d4da0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MulanPSL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownCode   = 500
	UnknownReason = ""
)

Variables

View Source
var (
	// optional int32 code = 1109;
	E_Code = &file_errors_proto_extTypes[1]
)

Extension fields to descriptorpb.EnumValueOptions.

View Source
var (
	// optional int32 default_code = 1108;
	E_DefaultCode = &file_errors_proto_extTypes[0]
)

Extension fields to descriptorpb.EnumOptions.

View Source
var File_errors_proto protoreflect.FileDescriptor

Functions

func As

func As(err error, target any) bool

func Code

func Code(err error) int

func Errorf

func Errorf(code int, reason string, format string, a ...any) error

func Is

func Is(err, target error) bool

func IsBadRequest

func IsBadRequest(err error) bool

func IsClientClosed

func IsClientClosed(err error) bool

func IsConflict

func IsConflict(err error) bool

func IsForbidden

func IsForbidden(err error) bool

func IsGatewayTimeout

func IsGatewayTimeout(err error) bool

func IsInternalServer

func IsInternalServer(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func IsServiceUnavailable

func IsServiceUnavailable(err error) bool

func IsUnauthorized

func IsUnauthorized(err error) bool

func Reason

func Reason(err error) string

func Unwrap

func Unwrap(err error) error

Types

type Error

type Error struct {
	Status // 基本 = google.golang.org/grpc/internal/status.Status
	// contains filtered or unexported fields
}

func BadRequest

func BadRequest(reason, message string) *Error

func ClientClosed

func ClientClosed(reason, message string) *Error

func Clone

func Clone(err *Error) *Error

func Conflict

func Conflict(reason, message string) *Error

func Forbidden

func Forbidden(reason, message string) *Error

func FromError

func FromError(err error) *Error

FromError 其中包含从GRPC.Status(error)转换

func GatewayTimeout

func GatewayTimeout(reason, message string) *Error

func InternalServer

func InternalServer(reason, message string) *Error

func New

func New(code int, reason, message string) *Error

func Newf

func Newf(code int, reason string, format string, a ...any) *Error

func NotFound

func NotFound(reason, message string) *Error

func ServiceUnavailable

func ServiceUnavailable(reason, message string) *Error

func Unauthorized

func Unauthorized(reason, message string) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) GRPCStatus

func (e *Error) GRPCStatus() *status.Status

GRPCStatus 转换成GRPC的error结构

func (*Error) Is

func (e *Error) Is(err error) bool

Is matches each error in the chain with the target value. package errors.Is(err, target error) bool: interface{ Is(error) bool }

func (*Error) Unwrap

func (e *Error) Unwrap() error

func (*Error) WithCause

func (e *Error) WithCause(cause error) *Error

func (*Error) WithMetadata

func (e *Error) WithMetadata(md map[string]string) *Error

type Status

type Status struct {
	Code     int32             `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	Reason   string            `protobuf:"bytes,2,opt,name=reason,proto3" json:"reason,omitempty"`
	Message  string            `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"`
	Metadata map[string]string `` /* 157-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*Status) Descriptor deprecated

func (*Status) Descriptor() ([]byte, []int)

Deprecated: Use Status.ProtoReflect.Descriptor instead.

func (*Status) GetCode

func (x *Status) GetCode() int32

func (*Status) GetMessage

func (x *Status) GetMessage() string

func (*Status) GetMetadata

func (x *Status) GetMetadata() map[string]string

func (*Status) GetReason

func (x *Status) GetReason() string

func (*Status) ProtoMessage

func (*Status) ProtoMessage()

func (*Status) ProtoReflect

func (x *Status) ProtoReflect() protoreflect.Message

func (*Status) Reset

func (x *Status) Reset()

func (*Status) String

func (x *Status) String() string

Jump to

Keyboard shortcuts

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