基于 grpc-gateway 的,统一处理由 grpc 返回给 http 的数据。包括以下几点:
http统一返回的json格式: 由code/msg/data组成- 按照谷歌标准将 
grpc错误码转成http的错误码 - 请求成功后,处理后返回给前端只有一个 
response 
引入包
go get "github.com/janrs-io/[email protected]"在 grpc-gateway 启动 http 服务的中间件添加以下方法:
mux := runtime.NewServeMux(
	runtime.WithErrorHandler(Jgrpc_response.HttpErrorHandler),
	runtime.WithForwardResponseOption(Jgrpc_response.HttpSuccessResponseModifier),
	runtime.WithMarshalerOption("*", &Jgrpc_response.CustomMarshaller{}),
)当 rpc 按照以上格式返回后,添加了 http 处理中间件会自动处理 rpc 返回的数据然后返回给前端。