grpcutil

package
v1.7.0-dev-20190926 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: Apache-2.0 Imports: 14 Imported by: 34

Documentation

Overview

Package grpcutil adds some helpers that make writing grpc servers and clients a little easier.

Index

Constants

View Source
const (
	ErrListenerClosed = fault.Const("pipeListener closed")
)

Variables

This section is empty.

Functions

func Client

func Client(ctx context.Context, target string, task ClientTask, options ...grpc.DialOption) error

Client dials a grpc server, and runs the task with the connection, and closes the connection again before returning. It also installs the standard options we normally use.

func Dial

func Dial(ctx context.Context, target string, options ...grpc.DialOption) (*grpc.ClientConn, error)

Dial connects to a grpc server, and returns the connection. It also installs the standard options we normally use.

func DialPipe

func DialPipe(addr string) (net.Conn, error)

DialPipe connects to listeners obtained with NewPipeListener.

func DialPipeCtx

func DialPipeCtx(ctx context.Context, addr string) (net.Conn, error)

DialPipeCtx connects to listeners obtained with NewPipeListener, and errors if the context is canceled.

func GetDialer

func GetDialer(ctx context.Context) func(string, time.Duration) (net.Conn, error)

GetDialer takes a context and returns a grpc-compatible dialer function that will fail if the context is stopped or if the specified timeout passes.

func NewPipeListener

func NewPipeListener(addr string) net.Listener

NewPipeListener returns a net.Listener that accepts connections from DialPipe. This listener will use net.Pipe() to create a pair of endpoints and match them together. addr is used to distinguish between multiple listeners. Multiple listeners can accept connections on the same address.

func Serve

func Serve(ctx context.Context, address string, prepare PrepareTask, options ...grpc.ServerOption) error

Serve prepares and runs a grpc server on the specified address. It also installs the standard options we normally use.

func ServeWithListener

func ServeWithListener(ctx context.Context, listener net.Listener, prepare PrepareTask, options ...grpc.ServerOption) error

ServeWithListener prepares and runs a grpc server using the specified net.Listener. It also installs the standard options we normally use.

func ToProducer

func ToProducer(stream interface{}) event.Producer

ToProducer adapts an input grpc stream to an event producer.

Types

type ClientTask

type ClientTask func(context.Context, *grpc.ClientConn) error

ClientTask is invoked with an open grpc connection by Client.

type PrepareTask

type PrepareTask func(context.Context, net.Listener, *grpc.Server) error

PrepareTask is called to add the services to a grpc server before it starts running.

Jump to

Keyboard shortcuts

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