mux

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAddress = errors.New("not address")
	ErrNotFound   = errors.New("not found")
)

Functions

func NewMuxWithConfig

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

Types

type Config

type Config struct {
	Patterns []*Pattern
	Routes   map[string]modules.Handlers
	NotFound string
}

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) Handle

func (m *Mux) Handle(pattern string, handler modules.Handler) error

Handle registers the handler for the given pattern in the Mux.

func (*Mux) Handler

func (m *Mux) Handler(r io.Reader) (handler modules.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 modules.Handler) error

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

func (*Mux) Pattern

func (m *Mux) Pattern(name string, pattern string)

func (*Mux) ServeConn

func (m *Mux) ServeConn(ctx context.Context, conn net.Conn)

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

func (*Mux) UnmarshalJSON

func (m *Mux) UnmarshalJSON(data []byte) error

type Pattern

type Pattern struct {
	Name    string
	Pattern string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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