Documentation
¶
Index ¶
- Constants
- Variables
- func CodeToError(c codes.Code) string
- func CodeToStatus(code codes.Code) int
- func DisableRecover()
- func ExtractFields(tagsData map[string]string) logging.Fields
- func HandlerGRPCService(mux *runtime.ServeMux, server interface{}, v grpc.MethodDesc) func(w http.ResponseWriter, r *http.Request, _ map[string]string)
- func Redirect(url string) *httpbody.HttpBody
- func RegisterErrorCodes(codeErrors map[int32]string)
- func TraceMiddleWare(h http.Handler) http.Handler
- func WriteHTTPErrorResponse(w http.ResponseWriter, r *http.Request, err error)
- type MuxError
- func (*MuxError) Descriptor() ([]byte, []int)deprecated
- func (x *MuxError) GetCode() uint32
- func (x *MuxError) GetDetails() []*anypb.Any
- func (x *MuxError) GetMessage() string
- func (*MuxError) ProtoMessage()
- func (x *MuxError) ProtoReflect() protoreflect.Message
- func (x *MuxError) Reset()
- func (x *MuxError) String() string
- type MuxOption
- type MuxServe
- type Optional
- func WithBodyMarshaler(ms runtime.Marshaler) Optional
- func WithBodyWriter(b bodyReWriterFunc) Optional
- func WithErrorHandler(fn runtime.ErrorHandlerFunc) Optional
- func WithErrorMarshaler(ms runtime.Marshaler) Optional
- func WithMiddleWares(middleWares ...func(http.Handler) http.Handler) Optional
- func WithRunTimeOpts(opts runtime.ServeMuxOption) Optional
- func WithoutHTTPStatus() Optional
Constants ¶
const ( RequestIDHeader = "x-request-id" CaptchaTokenHeader = "x-captcha-token" )
Variables ¶
var File_server_mux_mux_error_proto protoreflect.FileDescriptor
Functions ¶
func ExtractFields ¶
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 RegisterErrorCodes ¶
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 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) GetDetails ¶
func (*MuxError) GetMessage ¶
func (*MuxError) ProtoMessage ¶
func (*MuxError) ProtoMessage()
func (*MuxError) ProtoReflect ¶
func (x *MuxError) ProtoReflect() protoreflect.Message
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 ¶
NewMuxServe allocates and returns a new MuxServe.
func (*MuxServe) Handle ¶
func (srv *MuxServe) Handle(method, path string, h runtime.HandlerFunc)
Handle handle http path
type Optional ¶
type Optional func(*MuxOption)
Optional the Options for this module
func WithErrorHandler ¶
func WithErrorHandler(fn runtime.ErrorHandlerFunc) Optional
WithErrorHandler
func WithMiddleWares ¶
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.