mux

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = fmt.Errorf("error not found")
)

Functions

func Get

func Get(name string) (string, bool)

func NewMuxWithConfig

func NewMuxWithConfig(conf *Config) (stream.Handler, error)

NewProtoMux create a new Mux with config.

func RegisterRegexp

func RegisterRegexp(name string, pattern string)

func Unread

func Unread(reader io.Reader, prefix []byte) io.Reader

func UnreadStream

func UnreadStream(rwc stream.Stream, prefix []byte) stream.Stream

func UnwrapUnread

func UnwrapUnread(reader io.Reader) (io.Reader, []byte)

func UnwrapUnreadStream

func UnwrapUnreadStream(rwc stream.Stream) (stream.Stream, []byte)

Types

type Config

type Config struct {
	Routes   []*Route
	NotFound stream.Handler
}

type Mux

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

Mux is an Applicative protocol multiplexer It matches the prefix of each incoming reader against a list of registered patterns and calls the handler for the pattern that most closely matches the Handler.

func NewMux

func NewMux() *Mux

NewProtoMux create a new Mux.

func (*Mux) HandlePrefix

func (m *Mux) HandlePrefix(prefix string, handler stream.Handler) error

func (*Mux) HandleRegexp

func (m *Mux) HandleRegexp(pattern string, handler stream.Handler) error

func (*Mux) Handler

func (m *Mux) Handler(r io.Reader) (handler stream.Handler, prefix []byte, err error)

Handler returns most matching handler and prefix bytes data to use for the given reader.

func (*Mux) NotFound

func (m *Mux) NotFound(handler stream.Handler) error

NotFound replies to the handler with an Handler not found error.

func (*Mux) ServeStream

func (m *Mux) ServeStream(ctx context.Context, stm stream.Stream)

ServeStream dispatches the reader to the handler whose pattern most closely matches the reader.

type Route

type Route struct {
	Pattern string `json:",omitempty"`
	Regexp  string `json:",omitempty"`
	Prefix  string `json:",omitempty"`
	Handler stream.Handler
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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