typemux

package
v2.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2021 License: MIT Imports: 5 Imported by: 17

Documentation

Overview

Package typemux offers an improved muxrpc.HandlerMux (think HTTP router). compared to the first draft, this one offers specialed handler functions for the different call types (async, source, sink) to reduce boilerplate in handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncFunc

type AsyncFunc func(context.Context, *muxrpc.Request) (interface{}, error)

func (AsyncFunc) HandleAsync

func (af AsyncFunc) HandleAsync(ctx context.Context, r *muxrpc.Request) (interface{}, error)

type AsyncHandler

type AsyncHandler interface {
	HandleAsync(context.Context, *muxrpc.Request) (interface{}, error)
}

type DuplexFunc

type DuplexFunc func(context.Context, *muxrpc.Request, *muxrpc.ByteSource, *muxrpc.ByteSink) error

DuplexFunc is a utility to fulfill DuplexHandler just as a function, not a type with the named method

func (DuplexFunc) HandleDuplex

func (sf DuplexFunc) HandleDuplex(ctx context.Context, r *muxrpc.Request, src *muxrpc.ByteSource, snk *muxrpc.ByteSink) error

HandleDuplex implements the duplex handler for the function

type DuplexHandler

type DuplexHandler interface {
	HandleDuplex(context.Context, *muxrpc.Request, *muxrpc.ByteSource, *muxrpc.ByteSink) error
}

DuplexHandler initiates a 'duplex' call. The handler receives data from the peer through the passed source

type HandlerMux

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

func New

func New(log log.Logger) HandlerMux

func (*HandlerMux) HandleCall

func (hm *HandlerMux) HandleCall(ctx context.Context, req *muxrpc.Request)

func (*HandlerMux) HandleConnect

func (hm *HandlerMux) HandleConnect(ctx context.Context, edp muxrpc.Endpoint)

func (*HandlerMux) Handled

func (hm *HandlerMux) Handled(m muxrpc.Method) bool

func (*HandlerMux) RegisterAsync

func (hm *HandlerMux) RegisterAsync(m muxrpc.Method, h AsyncHandler)

RegisterAsync registers a 'async' call for name method

func (*HandlerMux) RegisterDuplex

func (hm *HandlerMux) RegisterDuplex(m muxrpc.Method, h DuplexHandler)

RegisterDuplex registers a 'sink' call for name method

func (*HandlerMux) RegisterSink

func (hm *HandlerMux) RegisterSink(m muxrpc.Method, h SinkHandler)

RegisterSink registers a 'sink' call for name method

func (*HandlerMux) RegisterSource

func (hm *HandlerMux) RegisterSource(m muxrpc.Method, h SourceHandler)

RegisterSource registers a 'source' call for name method

type SinkFunc

type SinkFunc func(context.Context, *muxrpc.Request, *muxrpc.ByteSource) error

SinkFunc is a utility to fulfill SinkHandler just as a function, not a type with the named method

func (SinkFunc) HandleSink

func (sf SinkFunc) HandleSink(ctx context.Context, r *muxrpc.Request, src *muxrpc.ByteSource) error

HandleSink implements the sink handler for the function

type SinkHandler

type SinkHandler interface {
	HandleSink(context.Context, *muxrpc.Request, *muxrpc.ByteSource) error
}

SinkHandler initiates a 'sink' call. The handler receives data from the peer through the passed source

type SourceFunc

type SourceFunc func(context.Context, *muxrpc.Request, *muxrpc.ByteSink) error

func (SourceFunc) HandleSource

func (sf SourceFunc) HandleSource(ctx context.Context, r *muxrpc.Request, src *muxrpc.ByteSink) error

type SourceHandler

type SourceHandler interface {
	HandleSource(context.Context, *muxrpc.Request, *muxrpc.ByteSink) error
}

SourceHandler initiates a 'source' call, so the handler is supposed to send a stream of stuff to the peer.

Jump to

Keyboard shortcuts

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