Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CodeToError ¶ added in v1.2.0
CodeToError translate grpc codes to error
func DefaultHTTPError ¶ added in v1.2.3
func DefaultHTTPError(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, _ *http.Request, err error)
DefaultHTTPError is the default implementation of HTTPError. If "err" is an error from gRPC system, the function replies with the status code mapped by HTTPStatusFromCode. If otherwise, it replies with http.StatusInternalServerError.
The response body returned by this function is a JSON object, which contains a member whose key is "error" and whose value is err.Error().
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)
Types ¶
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.