Documentation ¶
Index ¶
- Variables
- func CodeToError(c codes.Code) string
- func DefaultHTTPErrorHandler(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, ...)
- func DefaultHeaderMatcher(key string) (string, bool)
- func SetCustomErrorCodes(codeErrors map[int32]string)
- func Validate(ctx context.Context, req interface{}) error
- func WriteHTTPErrorResponse(w http.ResponseWriter, err error)
- type Error
- func (*Error) Descriptor() ([]byte, []int)deprecated
- func (x *Error) GetDetails() []*any.Any
- func (x *Error) GetError() string
- func (x *Error) GetErrorCode() int32
- func (x *Error) GetErrorDescription() string
- func (*Error) ProtoMessage()
- func (x *Error) ProtoReflect() protoreflect.Message
- func (x *Error) Reset()
- func (x *Error) String() string
- type MuxedGrpc
- type ServeMux
- type StreamError
- func (*StreamError) Descriptor() ([]byte, []int)deprecated
- func (x *StreamError) GetDetails() []*any.Any
- func (x *StreamError) GetErrorDescription() string
- func (x *StreamError) GetGrpcCode() int32
- func (x *StreamError) GetHttpCode() int32
- func (x *StreamError) GetHttpStatus() string
- func (*StreamError) ProtoMessage()
- func (x *StreamError) ProtoReflect() protoreflect.Message
- func (x *StreamError) Reset()
- func (x *StreamError) String() string
Constants ¶
This section is empty.
Variables ¶
var File_error_proto protoreflect.FileDescriptor
Functions ¶
func CodeToError ¶ added in v1.2.0
CodeToError translate grpc codes to error
func DefaultHTTPErrorHandler ¶ added in v1.5.2
func DefaultHTTPErrorHandler(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error)
DefaultHTTPErrorHandler is the default error handler. If "err" is a gRPC Status, the function replies with the status code mapped by HTTPStatusFromCode. If otherwise, it replies with http.StatusInternalServerError.
The response body written by this function is a Status message marshaled by the Marshaler.
func DefaultHeaderMatcher ¶ added in v1.4.4
DefaultHeaderMatcher default header matcher
func SetCustomErrorCodes ¶ added in v1.2.7
SetCustomErrorCodes set custom error codes for DefaultHTTPError the map[int32]string is compact to protobuf's ENMU_name 2*** HTTP status 200 4*** HTTP status 400 5*** AND other HTTP status 500 For exp: in proto
enum CommonError { captcha_required = 4001; invalid_captcha = 4002; }
in code grpcmux.SetCustomErrorCodes(common.CommonError_name)
func WriteHTTPErrorResponse ¶ added in v1.4.4
func WriteHTTPErrorResponse(w http.ResponseWriter, err error)
WriteHTTPErrorResponse set HTTP status code and write error description to the body.
Types ¶
type Error ¶ added in v1.4.4
type Error struct { Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"` // This is to make the error more compatible with users that expect errors to be Status objects: // https://github.com/grpc/grpc/blob/master/src/proto/grpc/status/status.proto // It should be the exact same message as the Error field. ErrorCode int32 `protobuf:"varint,2,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"` ErrorDescription string `protobuf:"bytes,3,opt,name=error_description,json=errorDescription,proto3" json:"error_description,omitempty"` Details []*any.Any `protobuf:"bytes,4,rep,name=details,proto3" json:"details,omitempty"` // contains filtered or unexported fields }
Error is the generic error returned from unary RPCs.
func (*Error) Descriptor
deprecated
added in
v1.4.4
func (*Error) GetDetails ¶ added in v1.4.4
func (*Error) GetErrorCode ¶ added in v1.4.4
func (*Error) GetErrorDescription ¶ added in v1.4.4
func (*Error) ProtoMessage ¶ added in v1.4.4
func (*Error) ProtoMessage()
func (*Error) ProtoReflect ¶ added in v1.4.4
func (x *Error) ProtoReflect() protoreflect.Message
type MuxedGrpc ¶ added in v1.2.1
type MuxedGrpc struct { }
MuxedGrpc check the context is by mux grpc
type ServeMux ¶
ServeMux the custom serve mux that implement grpc ServeMux to simplify the http restful
func NewServeMux ¶
func NewServeMux(opts ...runtime.ServeMuxOption) *ServeMux
NewServeMux allocates and returns a new ServeMux.
type StreamError ¶ added in v1.4.4
type StreamError struct { GrpcCode int32 `protobuf:"varint,1,opt,name=grpc_code,json=grpcCode,proto3" json:"grpc_code,omitempty"` HttpCode int32 `protobuf:"varint,2,opt,name=http_code,json=httpCode,proto3" json:"http_code,omitempty"` ErrorDescription string `protobuf:"bytes,3,opt,name=error_description,json=errorDescription,proto3" json:"error_description,omitempty"` HttpStatus string `protobuf:"bytes,4,opt,name=http_status,json=httpStatus,proto3" json:"http_status,omitempty"` Details []*any.Any `protobuf:"bytes,5,rep,name=details,proto3" json:"details,omitempty"` // contains filtered or unexported fields }
StreamError is a response type which is returned when streaming rpc returns an error.
func (*StreamError) Descriptor
deprecated
added in
v1.4.4
func (*StreamError) Descriptor() ([]byte, []int)
Deprecated: Use StreamError.ProtoReflect.Descriptor instead.
func (*StreamError) GetDetails ¶ added in v1.4.4
func (x *StreamError) GetDetails() []*any.Any
func (*StreamError) GetErrorDescription ¶ added in v1.4.4
func (x *StreamError) GetErrorDescription() string
func (*StreamError) GetGrpcCode ¶ added in v1.4.4
func (x *StreamError) GetGrpcCode() int32
func (*StreamError) GetHttpCode ¶ added in v1.4.4
func (x *StreamError) GetHttpCode() int32
func (*StreamError) GetHttpStatus ¶ added in v1.4.4
func (x *StreamError) GetHttpStatus() string
func (*StreamError) ProtoMessage ¶ added in v1.4.4
func (*StreamError) ProtoMessage()
func (*StreamError) ProtoReflect ¶ added in v1.4.4
func (x *StreamError) ProtoReflect() protoreflect.Message
func (*StreamError) Reset ¶ added in v1.4.4
func (x *StreamError) Reset()
func (*StreamError) String ¶ added in v1.4.4
func (x *StreamError) String() string