Documentation ¶
Overview ¶
Package grpc tRPC-Go grpc 协议
Index ¶
- Variables
- func NewServerStreamTransport(opt ...transport.ServerTransportOption) transport.ServerStreamTransport
- func NewServerTransport(opt ...transport.ServerTransportOption) transport.ServerTransport
- func NewStreamClient() stream.Client
- func ParseGRPCMetadata(ctx context.Context) map[string][]string
- func Register(serviceName string, metadata string, methodInfos []RegisterMethodsInfo) error
- func RegisterStream(serviceName, metadata string, streamInfos []server.StreamDesc, svr interface{}, ...) error
- func StreamHandler(srv interface{}, s grpc.ServerStream) error
- func WithHeader(ctx context.Context, header *Header) context.Context
- func WithServerGRPCMetadata(ctx context.Context, key string, value []string)
- type ClientCodec
- type GrpcToTrpcLayer
- type GrpcToTrpcer
- type Header
- type RegisterInfo
- type RegisterMethodsInfo
- type RegisterStreamsInfo
- type ServerCodec
- type ServerStreamTransport
- type ServerTransport
- type StreamClient
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultServerCodec Default codec instance DefaultServerCodec = &ServerCodec{} // DefaultClientCodec Default client codec DefaultClientCodec = &ClientCodec{} )
var ContextKeyHeader = &contextHeader{}
ContextKeyHeader key in context to store Header
var DefaultClientTransport = &clientTransport{}
DefaultClientTransport default client communication layer
var DefaultServerStreamTransport = NewServerStreamTransport()
DefaultServerStreamTransport default server stream transport
var DefaultServerTransport = NewServerTransport(transport.WithReusePort(true))
DefaultServerTransport : Construct and encapsulate the grpc server transport instance
var DefaultStreamClient = NewStreamClient()
DefaultStreamClient Generate a new StreamClient
Functions ¶
func NewServerStreamTransport ¶
func NewServerStreamTransport(opt ...transport.ServerTransportOption) transport.ServerStreamTransport
NewServerStreamTransport Create grpc_stream transport
func NewServerTransport ¶
func NewServerTransport(opt ...transport.ServerTransportOption) transport.ServerTransport
NewServerTransport create transport
func NewStreamClient ¶
NewStreamClient Generate a new StreamClient
func ParseGRPCMetadata ¶
ParseGRPCMetadata Called by the trpc-go server to obtain the metadata of the client
func Register ¶
func Register(serviceName string, metadata string, methodInfos []RegisterMethodsInfo) error
Register All external routes used to statically register grpc service, and the mapping of the return type
func RegisterStream ¶
func RegisterStream(serviceName, metadata string, streamInfos []server.StreamDesc, svr interface{}, handlerType interface{}) error
RegisterStream Register grpc stream description information Keep the previous RegisterMethod method, which can be collected later
func StreamHandler ¶
func StreamHandler(srv interface{}, s grpc.ServerStream) error
StreamHandler Encapsulate trpc.Handler as grpcHandler
func WithHeader ¶
WithHeader trpc-go client call, set the md sent to the server, or accept the md from the server
Types ¶
type ClientCodec ¶
type ClientCodec struct{}
ClientCodec is the codec for the grpc client, does nothing
type GrpcToTrpcLayer ¶
GrpcToTrpcLayer implements GrpcToTrpcer and offers a handler of grpc server.
func (*GrpcToTrpcLayer) Handle ¶
func (g *GrpcToTrpcLayer) Handle(srv interface{}, ctx context.Context, dec func(interface{}) error, _ grpc.UnaryServerInterceptor) (out interface{}, err error)
Handle req and resp are passed to trpc-go through ctx, and req is obtained from ctx and written to resp in the
generated stub without repeated serialization.
Obtaining the input and output types of the method from GrpcRegisterInfoMap is still indispensable. If this piece
of code can be placed in the stub, there is no need to record the input and output types.
type GrpcToTrpcer ¶
type GrpcToTrpcer interface { Handle(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (out interface{}, err error) }
GrpcToTrpcer is an interface to represent handler of grpc server.
type Header ¶
type Header struct { Req interface{} // request Rsp interface{} // response InMetadata map[string][]string // metadata from client OutMetadata map[string][]string // metadata send to client }
Header stored in context to communicate with trpc
type RegisterInfo ¶
type RegisterInfo struct { Metadata string ServerFunc interface{} HandlerType interface{} MethodsInfo map[string]RegisterMethodsInfo StreamsInfo map[string]server.StreamDesc }
RegisterInfo grpc Information required for registration
type RegisterMethodsInfo ¶
RegisterMethodsInfo Register the content of the method
type RegisterStreamsInfo ¶
type RegisterStreamsInfo struct {
server.StreamDesc
}
RegisterStreamsInfo Register the content of the stream
type ServerCodec ¶
type ServerCodec struct { }
ServerCodec Server codec
type ServerStreamTransport ¶
type ServerStreamTransport struct {
// contains filtered or unexported fields
}
ServerStreamTransport transport layer
func (*ServerStreamTransport) Close ¶
func (t *ServerStreamTransport) Close(ctx context.Context)
Close When the server is abnormal, call Close to clean up the scene
func (*ServerStreamTransport) ListenAndServe ¶
func (t *ServerStreamTransport) ListenAndServe(ctx context.Context, opt ...transport.ListenServeOption) error
ListenAndServe Start grpc monitoring
type ServerTransport ¶
type ServerTransport struct {
// contains filtered or unexported fields
}
ServerTransport transport layer
func (*ServerTransport) ListenAndServe ¶
func (t *ServerTransport) ListenAndServe(ctx context.Context, opt ...transport.ListenServeOption) error
ListenAndServe process configuration
type StreamClient ¶
type StreamClient struct {
// contains filtered or unexported fields
}
StreamClient grpc.Stream client implementation
func (*StreamClient) NewStream ¶
func (s *StreamClient) NewStream(ctx context.Context, desc *client.ClientStreamDesc, method string, opt ...client.Option) (client.ClientStream, error)
NewStream Generate streamConn and store
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
servers/impl/trpc
Package trpc 实现接口
|
Package trpc 实现接口 |
clients/tgrpc_stream
Module
|
|
servers/tgrpc_stream
Module
|