memnet
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package memnet implements an in-memory network implementation.It is useful for dialing and listening on in-memory addressesin tests and other situations where you don't want to use thenetwork.
Index¶
Constants¶
const NetworkName = "mem"NetworkName is the network name returned bynet.Addr.Networkfornet.Conn.LocalAddr andnet.Conn.RemoteAddr from theConn type.
Variables¶
This section is empty.
Functions¶
Types¶
typeConn¶
type Conn interface {net.Conn// SetReadBlock blocks or unblocks the Read method of this Conn.// It reports an error if the existing value matches the new value,// or if the Conn has been Closed.SetReadBlock(bool)error// SetWriteBlock blocks or unblocks the Write method of this Conn.// It reports an error if the existing value matches the new value,// or if the Conn has been Closed.SetWriteBlock(bool)error}Conn is a net.Conn that can additionally have its reads and writes blocked and unblocked.
typeListener¶
type Listener struct {// NewConn, if non-nil, is called to create a new pair of connections// when dialing. If nil, NewConn is used.NewConn func(network, addrstring, maxBufint) (Conn,Conn)// contains filtered or unexported fields}Listener is a net.Listener using NewConn to create pairs of networkconnections connected in memory using a buffered pipe. It also provides aDial method to establish new connections.
typeNetwork¶added inv1.84.0
type Network struct {// contains filtered or unexported fields}Network implementsNetwork using an in-memory network, usuallyused for testing.
As of 2025-04-08, it only supports TCP.
Its zero value is a validnetx.Network implementation.
func (*Network)NewLocalTCPListener¶added inv1.84.0
typePipe¶
type Pipe struct {// contains filtered or unexported fields}Pipe implements an in-memory FIFO with timeouts.
func (*Pipe)Block¶
Block will cause all calls to Read and Write to block until they eithertimeout, are unblocked or the pipe is closed.
func (*Pipe)Read¶
Read implements io.Reader.Once the buffer is drained (i.e. after Close), subsequent calls willreturn io.EOF.
func (*Pipe)SetReadDeadline¶
SetReadDeadline sets the deadline for future Read calls.
func (*Pipe)SetWriteDeadline¶
SetWriteDeadline sets the deadline for future Write calls.