net

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDialerFactory added in v0.2.4

func RegisterDialerFactory(scheme []string, factory func(u *url.URL, dialer ContextDialer) (ContextDialer, error)) error

Types

type ContextDialer

type ContextDialer interface {
	// Returns connection if successful, or an error.
	// The context is used to cancel the dial. It will return a non-nil error if the context is done.
	// ctx should be ignored after connection is established.
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

A ContextDialer dials using a context.

func CreateDialer added in v0.2.4

func CreateDialer(u *url.URL, dialer ContextDialer) (ContextDialer, error)

type DialContextFunc added in v0.2.0

type DialContextFunc func(ctx context.Context, network, address string) (net.Conn, error)

func (DialContextFunc) Dial added in v0.2.0

func (f DialContextFunc) Dial(network, address string) (net.Conn, error)

func (DialContextFunc) DialContext added in v0.2.0

func (f DialContextFunc) DialContext(ctx context.Context, network, address string) (net.Conn, error)

type DialFunc added in v0.2.0

type DialFunc func(network, address string) (net.Conn, error)

func (DialFunc) Dial added in v0.2.0

func (f DialFunc) Dial(network, address string) (net.Conn, error)

func (DialFunc) DialContext added in v0.2.0

func (f DialFunc) DialContext(ctx context.Context, network, address string) (net.Conn, error)

type Dialer

type Dialer interface {
	// Dial connects to the given address
	Dial(network, addr string) (c net.Conn, err error)
}

A Dialer is a means to establish a connection. Custom dialers should also implement ContextDialer.

type Forwarder

type Forwarder interface {
	// Forward() a conn and someone may Accept() it from Listener
	// Returns nil if the connection is accepted.
	// ctx should be ignored after connection is accepted.
	Forward(ctx context.Context, c net.Conn) error
}

type ForwarderFunc

type ForwarderFunc func(ctx context.Context, c net.Conn) error

func (ForwarderFunc) Forward

func (f ForwarderFunc) Forward(ctx context.Context, c net.Conn) error

type Listener

type Listener net.Listener

type OverrideAddr added in v0.2.4

type OverrideAddr struct {
	OverrideNetwork string
	OverrideAddress string
}

func (*OverrideAddr) Network added in v0.2.4

func (a *OverrideAddr) Network() string

func (*OverrideAddr) String added in v0.2.4

func (a *OverrideAddr) String() string

type OverrideConn added in v0.2.4

type OverrideConn struct {
	net.Conn
	OverrideLocalAddr  net.Addr
	OverrideRemoteAddr net.Addr
}

func (*OverrideConn) LocalAddr added in v0.2.4

func (c *OverrideConn) LocalAddr() net.Addr

func (*OverrideConn) RemoteAddr added in v0.2.4

func (c *OverrideConn) RemoteAddr() net.Addr

type OverrideListener added in v0.2.4

type OverrideListener struct {
	net.Listener
	OverrideLocalAddr  bool
	OverrideRemoteAddr bool
}

func (*OverrideListener) Accept added in v0.2.4

func (l *OverrideListener) Accept() (c net.Conn, e error)

type PipeListener added in v0.2.5

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

func ListenPipe

func ListenPipe() *PipeListener

ListenPipe creates a pipeListener that implement net.Listener and Dialer.

The returned Listener and Dialer operate on the same in-memory channel. Calling Dial on the Dialer will return a Conn that can be used to communicate with a Conn accepted from the Listener.

func (*PipeListener) Accept added in v0.2.5

func (l *PipeListener) Accept() (c net.Conn, e error)

Accept waits for and returns the next connection to the listener.

func (*PipeListener) Addr added in v0.2.5

func (l *PipeListener) Addr() net.Addr

Addr returns the listener's network address.

func (*PipeListener) Close added in v0.2.5

func (l *PipeListener) Close() (e error)

Close closes the listener. Any blocked Accept operations will be unblocked and return errors.

func (*PipeListener) Dial added in v0.2.5

func (l *PipeListener) Dial(network, addr string) (net.Conn, error)

func (*PipeListener) DialContext added in v0.2.5

func (l *PipeListener) DialContext(ctx context.Context, network, addr string) (conn net.Conn, e error)

func (*PipeListener) Forward added in v0.2.5

func (l *PipeListener) Forward(ctx context.Context, conn net.Conn) (e error)

type PrefixConn

type PrefixConn struct {
	net.Conn
	Prefix io.Reader
}

PrefixConn will first read Prefix until EOF, and then read the content from Conn.

func (*PrefixConn) Read

func (b *PrefixConn) Read(p []byte) (n int, err error)

func (*PrefixConn) ReadFrom added in v0.2.0

func (b *PrefixConn) ReadFrom(r io.Reader) (n int64, err error)

func (*PrefixConn) WriteTo added in v0.2.0

func (b *PrefixConn) WriteTo(w io.Writer) (n int64, err error)

type ServeMux

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

ServeMux will forward the connection (Conn) to different Forwarders based on the rules.

func (*ServeMux) Forward

func (r *ServeMux) Forward(ctx context.Context, c net.Conn) error

func (*ServeMux) HandlePrefix

func (r *ServeMux) HandlePrefix(prefix []byte, forwarder Forwarder)

func (*ServeMux) HandleTLSProto added in v0.2.0

func (r *ServeMux) HandleTLSProto(proto string, forwarder Forwarder)

Directories

Path Synopsis
cookiejar
Package cookiejar implements an in-memory RFC 6265-compliant http.CookieJar.
Package cookiejar implements an in-memory RFC 6265-compliant http.CookieJar.

Jump to

Keyboard shortcuts

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