grpcmux

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2020 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_error_proto protoreflect.FileDescriptor

Functions

func CodeToError added in v1.2.0

func CodeToError(c codes.Code) string

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

func DefaultHeaderMatcher(key string) (string, bool)

DefaultHeaderMatcher default header matcher

func SetCustomErrorCodes added in v1.2.7

func SetCustomErrorCodes(codeErrors map[int32]string)

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 Validate added in v1.5.2

func Validate(ctx context.Context, req interface{}) error

Validate by the contxt

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) Descriptor() ([]byte, []int)

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) GetDetails added in v1.4.4

func (x *Error) GetDetails() []*any.Any

func (*Error) GetError added in v1.4.4

func (x *Error) GetError() string

func (*Error) GetErrorCode added in v1.4.4

func (x *Error) GetErrorCode() int32

func (*Error) GetErrorDescription added in v1.4.4

func (x *Error) GetErrorDescription() string

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

func (*Error) Reset added in v1.4.4

func (x *Error) Reset()

func (*Error) String added in v1.4.4

func (x *Error) String() string

type MuxedGrpc added in v1.2.1

type MuxedGrpc struct {
}

MuxedGrpc check the context is by mux grpc

type ServeMux

type ServeMux struct {
	*runtime.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.

func (*ServeMux) Handle

func (s *ServeMux) Handle(method string, path string, h runtime.HandlerFunc)

Handle associates "h" to the pair of HTTP method and path pattern.

func (*ServeMux) ServeHTTP

func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP add ctx from http request

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

Directories

Path Synopsis
pkg/go
Package pb is a reverse proxy.
Package pb is a reverse proxy.

Jump to

Keyboard shortcuts

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