grpcutil

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMustSpecifyRegisterFunc is used when a register func is nil.
	ErrMustSpecifyRegisterFunc = errors.New("must specify registerFunc")
)
View Source
var (
	// MaxMsgSize is used to define the GRPC frame size
	MaxMsgSize = 20 * 1024 * 1024
)

Functions

func Chunk added in v1.4.5

func Chunk(data []byte, chunkSize int) [][]byte

Chunk splits a piece of data up, this is useful for splitting up data that's bigger than MaxMsgSize

func ChunkReader added in v1.4.6

func ChunkReader(r io.Reader, f func([]byte) error) (int, error)

ChunkReader splits a reader into reasonably sized chunks for the purpose of transmitting the chunks over gRPC. For each chunk, it calls the given function.

func GetBuffer added in v1.4.6

func GetBuffer() []byte

GetBuffer returns a buffer. The buffer may or may not be freshly allocated, and it may or may not be zero-ed.

func NewStreamingBytesReader added in v1.3.5

func NewStreamingBytesReader(streamingBytesClient StreamingBytesClient) io.Reader

NewStreamingBytesReader returns an io.Reader for a StreamingBytesClient.

func NewStreamingBytesWriter added in v1.3.5

func NewStreamingBytesWriter(streamingBytesServer StreamingBytesServer) io.Writer

NewStreamingBytesWriter returns an io.Writer for a StreamingBytesServer.

func PutBuffer added in v1.4.6

func PutBuffer(buf []byte)

PutBuffer returns the buffer to the pool.

func Serve added in v1.3.5

func Serve(
	registerFunc func(*grpc.Server),
	options ServeOptions,
	serveEnv ServeEnv,
) (retErr error)

Serve serves stuff.

func WriteFromStreamingBytesClient added in v1.3.5

func WriteFromStreamingBytesClient(streamingBytesClient StreamingBytesClient, writer io.Writer) error

WriteFromStreamingBytesClient writes from the StreamingBytesClient to the io.Writer.

func WriteToStreamingBytesServer added in v1.3.5

func WriteToStreamingBytesServer(reader io.Reader, streamingBytesServer StreamingBytesServer) error

WriteToStreamingBytesServer writes the data from the io.Reader to the StreamingBytesServer.

Types

type Dialer

type Dialer interface {
	Dial(address string) (*grpc.ClientConn, error)
	CloseConns() error
}

Dialer defines a grpc.ClientConn connection dialer.

func NewDialer

func NewDialer(opts ...grpc.DialOption) Dialer

NewDialer creates a Dialer.

type Pool added in v1.4.6

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

Pool stores a pool of grpc connections to, it's useful in places where you would otherwise need to create several connections.

func NewPool added in v1.4.6

func NewPool(address string, size int, opts ...grpc.DialOption) *Pool

NewPool creates a new connection pool, size is the maximum number of connections that it will cache. There is no limit to he number of connections that it can provide.

func (*Pool) Close added in v1.4.6

func (p *Pool) Close() error

Close closes all connections stored in the pool, it returns an error if any of the calls to Close error.

func (*Pool) Get added in v1.4.6

func (p *Pool) Get(ctx context.Context) (*grpc.ClientConn, error)

Get returns a new connection, unlike sync.Pool if it has a cached connection it will always return it. Otherwise it will create a new one. Get errors only when it needs to Dial a new connection and that process fails.

func (*Pool) Put added in v1.4.6

func (p *Pool) Put(conn *grpc.ClientConn) error

Put returns the connection to the pool. If there are more than `size` connections already cached in the pool the connection will be closed. Put errors only when it Closes a connection and that call errors.

type ServeEnv added in v1.3.5

type ServeEnv struct {
	// Default is 7070.
	GRPCPort uint16 `env:"GRPC_PORT,default=7070"`
}

ServeEnv are environment variables for serving.

type ServeOptions added in v1.3.5

type ServeOptions struct {
	Version    *versionpb.Version
	MaxMsgSize int
}

ServeOptions represent optional fields for serving.

type StreamingBytesClient added in v1.3.5

type StreamingBytesClient interface {
	Recv() (*types.BytesValue, error)
}

StreamingBytesClient represents a client for an rpc method of the form:

rpc Foo(Bar) returns (stream google.protobuf.BytesValue) {}

type StreamingBytesServer added in v1.3.5

type StreamingBytesServer interface {
	Send(bytesValue *types.BytesValue) error
}

StreamingBytesServer represents a server for an rpc method of the form:

rpc Foo(Bar) returns (stream google.protobuf.BytesValue) {}

Jump to

Keyboard shortcuts

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