grpc

package module
v0.0.0-...-fb963d0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 25 Imported by: 1

Documentation

Index

Constants

View Source
const ContextKeyHeader = ContextKey("TRPC_GATEWAY_GRPC_HEADER")

ContextKeyHeader is the key for the GRPC header information in the context

View Source
const Protocol = "grpc"

Protocol is the protocol name

Variables

View Source
var (
	// DefaultServerCodec is the default encoding/decoding instance for the server
	DefaultServerCodec = &ServerCodec{}
	// DefaultClientCodec is the default encoding/decoding instance for the client
	DefaultClientCodec = &ClientCodec{}
)
View Source
var DefaultClientTransport = &ClientTransport{
	ConnectionPool: &Pool{},
}

DefaultClientTransport is the default client transport layer

Functions

func WithHeader

func WithHeader(ctx context.Context, header *Header) context.Context

WithHeader sets the GRPC header information in the context

func WithServerGRPCMetadata

func WithServerGRPCMetadata(ctx context.Context, key string, value []string)

WithServerGRPCMetadata is used for trpc-go server calls to send metadata

Types

type ClientCodec

type ClientCodec struct{}

ClientCodec is the codec for the grpc client, it does nothing

func (*ClientCodec) Decode

func (c *ClientCodec) Decode(_ codec.Msg, rspbody []byte) ([]byte, error)

Decode is the decoder for the grpc client, it does nothing

func (*ClientCodec) Encode

func (c *ClientCodec) Encode(_ codec.Msg, reqbody []byte) ([]byte, error)

Encode is the encoder for the grpc client, it does nothing

type ClientTransport

type ClientTransport struct {
	ConnectionPool ConnPool
	StreamClient   grpc.ClientStream
}

ClientTransport implements the transport.ClientTransport interface of trpc-go, using native grpc transport layer instead of trpc-go transport layer

func (*ClientTransport) RoundTrip

func (c *ClientTransport) RoundTrip(ctx context.Context, _ []byte,
	roundTripOpts ...transport.RoundTripOption) (rsp []byte, err error)

RoundTrip is the method that implements transport.ClientTransport, invoking native grpc client code

type ConnPool

type ConnPool interface {
	Get(address string, timeout time.Duration) (grpc.ClientConnInterface, error)
}

ConnPool connection pool

type ContextKey

type ContextKey string

ContextKey 定义 grpc 的 contextKey

type Header struct {
	Req         []byte      // request
	Rsp         []byte      // response
	InMetadata  metadata.MD // metadata from client
	OutMetadata metadata.MD // metadata sent to client
}

Header is stored in the context to communicate with trpc

func Head(ctx context.Context) *Header

Head retrieves the GRPC header information

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool implements a simple grpc connection pool

func (*Pool) Get

func (p *Pool) Get(address string, timeout time.Duration) (grpc.ClientConnInterface, error)

Get retrieves an available grpc client connection from the connection pool

type ServerCodec

type ServerCodec struct{}

ServerCodec is the server-side codec for encoding/decoding

func (*ServerCodec) Decode

func (s *ServerCodec) Decode(_ codec.Msg, reqbuf []byte) ([]byte, error)

Decode is used to decode the message

func (*ServerCodec) Encode

func (s *ServerCodec) Encode(_ codec.Msg, reqbuf []byte) ([]byte, error)

Encode is used to encode the message

Directories

Path Synopsis
Package mock_grpc is a generated GoMock package.
Package mock_grpc is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL