Documentation ¶
Overview ¶
Package grpcutil adds some helpers that make writing grpc servers and clients a little easier.
Index ¶
- Constants
- func Client(ctx context.Context, target string, task ClientTask, ...) error
- func Dial(ctx context.Context, target string, options ...grpc.DialOption) (*grpc.ClientConn, error)
- func DialPipe(addr string) (net.Conn, error)
- func DialPipeCtx(ctx context.Context, addr string) (net.Conn, error)
- func GetDialer(ctx context.Context) func(string, time.Duration) (net.Conn, error)
- func NewPipeListener(addr string) net.Listener
- func Serve(ctx context.Context, address string, prepare PrepareTask, ...) error
- func ServeWithListener(ctx context.Context, listener net.Listener, prepare PrepareTask, ...) error
- func ToProducer(stream interface{}) event.Producer
- type ClientTask
- type PrepareTask
Constants ¶
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 DialPipeCtx ¶
DialPipeCtx connects to listeners obtained with NewPipeListener, and errors if the context is canceled.
func GetDialer ¶
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 ¶
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 ¶
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.