prefix

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2020 License: MIT Imports: 11 Imported by: 0

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 NewPrefixWithConfig

func NewPrefixWithConfig(ctx context.Context, conf *Config) (stream.Handler, error)

NewPrefixWithConfig create a new Prefix 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 Prefix

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

Prefix 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 NewPrefix

func NewPrefix() *Prefix

NewPrefix create a new Prefix.

func (*Prefix) HandlePrefix

func (p *Prefix) HandlePrefix(prefix string, handler stream.Handler)

func (*Prefix) HandleRegexp

func (p *Prefix) HandleRegexp(pattern string, handler stream.Handler) error

func (*Prefix) Handler

func (p *Prefix) 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 (*Prefix) NotFound

func (p *Prefix) NotFound(handler stream.Handler)

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

func (*Prefix) ServeStream

func (p *Prefix) ServeStream(ctx context.Context, stm stream.Stream)

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

type ProtocolEnum

type ProtocolEnum string
const (
	ProtocolTLS    ProtocolEnum = "tls"
	ProtocolSocks4 ProtocolEnum = "socks4"
	ProtocolSocks5 ProtocolEnum = "socks5"
	ProtocolHTTP1  ProtocolEnum = "http1"
	ProtocolHTTP2  ProtocolEnum = "http2"
	ProtocolSSH    ProtocolEnum = "ssh"
)

type Route

type Route struct {
	Pattern ProtocolEnum `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