grpcmux

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2019 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CodeToError added in v1.2.0

func CodeToError(c codes.Code) string

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

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)

Types

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, req *http.Request)

ServeHTTP add ctx from http request

Directories

Path Synopsis
pb
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