mux

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: BSD-3-Clause Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestIDHeader    = "x-request-id"
	CaptchaTokenHeader = "x-captcha-token"
)

Variables

View Source
var File_server_mux_mux_error_proto protoreflect.FileDescriptor

Functions

func CodeToError

func CodeToError(c codes.Code) string

CodeToError

func CodeToStatus

func CodeToStatus(code codes.Code) int

CodeToStatus

func DisableRecover

func DisableRecover()

DisableRecover disable panic recover

func ExtractFields

func ExtractFields(tagsData map[string]string) logging.Fields

ExtractFields returns all fields from tags.

func HandlerGRPCService

func HandlerGRPCService(mux *runtime.ServeMux, server interface{}, v grpc.MethodDesc) func(w http.ResponseWriter,
	r *http.Request, _ map[string]string)

HandlerGRPCService

func Redirect

func Redirect(url string) *httpbody.HttpBody

Redirect response http body with redirect

func RegisterErrorCodes

func RegisterErrorCodes(codeErrors map[int32]string)

RegisterErrorCodes set custom error codes for DefaultHTTPError for exp: server.RegisterErrorCodes(pb.ErrorCode_name) 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 server.RegisterErrorCodes(common.CommonError_name)

func TraceMiddleWare

func TraceMiddleWare(h http.Handler) http.Handler

TraceMiddleWare add logger

func WriteHTTPErrorResponse

func WriteHTTPErrorResponse(w http.ResponseWriter, r *http.Request, err error)

WriteHTTPErrorResponse set HTTP status code and write error description to the body.

Types

type MuxError

type MuxError struct {
	Code    uint32       `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	Message string       `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	Details []*anypb.Any `protobuf:"bytes,3,rep,name=details,proto3" json:"details,omitempty"`
	// contains filtered or unexported fields
}

Error is the generic error returned from unary RPCs.

func (*MuxError) Descriptor deprecated

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

Deprecated: Use MuxError.ProtoReflect.Descriptor instead.

func (*MuxError) GetCode

func (x *MuxError) GetCode() uint32

func (*MuxError) GetDetails

func (x *MuxError) GetDetails() []*anypb.Any

func (*MuxError) GetMessage

func (x *MuxError) GetMessage() string

func (*MuxError) ProtoMessage

func (*MuxError) ProtoMessage()

func (*MuxError) ProtoReflect

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

func (*MuxError) Reset

func (x *MuxError) Reset()

func (*MuxError) String

func (x *MuxError) String() string

type MuxOption

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

type MuxServe

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

MuxServe the custom serve mux that implement grpc MuxServe to simplify the http restful.

func NewMuxServe

func NewMuxServe(logger *zap.Logger, opts ...Optional) *MuxServe

NewMuxServe allocates and returns a new MuxServe.

func (*MuxServe) Handle

func (srv *MuxServe) Handle(method, path string, h runtime.HandlerFunc)

Handle handle http path

func (*MuxServe) ServeHTTP

func (srv *MuxServe) ServeHTTP(w http.ResponseWriter, r *http.Request)

Handle handle http path

func (*MuxServe) ServeMux

func (srv *MuxServe) ServeMux() *runtime.ServeMux

ServeMux return grpc gateway server mux

type Optional

type Optional func(*MuxOption)

Optional the Options for this module

func WithBodyMarshaler

func WithBodyMarshaler(ms runtime.Marshaler) Optional

WithBodyMarshaler

func WithBodyWriter

func WithBodyWriter(b bodyReWriterFunc) Optional

WithBodyWriter

func WithErrorHandler

func WithErrorHandler(fn runtime.ErrorHandlerFunc) Optional

WithErrorHandler

func WithErrorMarshaler

func WithErrorMarshaler(ms runtime.Marshaler) Optional

WithErrorMarshaler

func WithMiddleWares

func WithMiddleWares(middleWares ...func(http.Handler) http.Handler) Optional

WithMiddleWares pluggable function that performs middle wares.

func WithRunTimeOpts

func WithRunTimeOpts(opts runtime.ServeMuxOption) Optional

WithRunTimeOpts with runtime MuxOption

func WithoutHTTPStatus

func WithoutHTTPStatus() Optional

WithoutHTTPStatus pluggable function that performs if use http status on response.

Jump to

Keyboard shortcuts

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