connartist

package module
v0.0.0-...-00cfc90 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 2 Imported by: 0

README

connartist

Go Report Card Documentation GitHub issues license

A small framework that makes it easy to extend, override, and mock net.Conn interface implementations.

Usage

Easily override the functions of a net.Conn implementation by wrapping it in a connartist.Conn and setting overrides as follows:

c, err := l.Accept()
if err != nil {
	fmt.Println(err)
	return
}

conn := connartist.New(c).
	WithRead(readHandler).
	WithWrite(writeHandler)
defer conn.Close()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn represents a net.Conn which extends the behavior of another net.Conn implementation.

func New

func New(conn net.Conn) *Conn

New returns a new Conn extending the given net.Conn

func (*Conn) Close

func (c *Conn) Close() error

Close runs the Close method on the conn

func (*Conn) LocalAddr

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

LocalAddr runs the LocalAddr method on the conn

func (*Conn) New

func (c *Conn) New() *Conn

New wraps a Conn within a new Conn to allow for multiple of the same function to be chained/layered together. This is particularly useful when dealing with messages that include multiple headers.

e.g. c.WithRead(fna).New().WithRead(fnb).New() and so on...

func (*Conn) Read

func (c *Conn) Read(b []byte) (n int, err error)

Read runs the Read method on the conn

func (*Conn) RemoteAddr

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

RemoteAddr runs the RemoteAddr method on the conn

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

SetDeadline runs the SetDeadline method on the conn

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline runs the SetReadDeadline method on the conn

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline runs the SetWriteDeadline method on the conn

func (*Conn) WithClose

func (c *Conn) WithClose(fn func(conn net.Conn) func() error) *Conn

WithClose overrides the Close method on the Conn

func (*Conn) WithLocalAddr

func (c *Conn) WithLocalAddr(fn func(conn net.Conn) func() net.Addr) *Conn

WithLocalAddr overrides the LocalAddr method on the Conn

func (*Conn) WithRead

func (c *Conn) WithRead(fn func(conn net.Conn) func([]byte) (int, error)) *Conn

WithRead overrides the Read method on the Conn

func (*Conn) WithRemoteAddr

func (c *Conn) WithRemoteAddr(fn func(conn net.Conn) func() net.Addr) *Conn

WithRemoteAddr overrides the RemoteAddr method on the Conn

func (*Conn) WithSetDeadline

func (c *Conn) WithSetDeadline(fn func(conn net.Conn) func(t time.Time) error) *Conn

WithSetDeadline overrides the SetDeadline method on the Conn

func (*Conn) WithSetReadDeadline

func (c *Conn) WithSetReadDeadline(fn func(conn net.Conn) func(t time.Time) error) *Conn

WithSetReadDeadline overrides the SetReadDeadline method on the Conn

func (*Conn) WithSetWriteDeadline

func (c *Conn) WithSetWriteDeadline(fn func(conn net.Conn) func(t time.Time) error) *Conn

WithSetWriteDeadline overrides the SetWriteDeadline method on the Conn

func (*Conn) WithWrite

func (c *Conn) WithWrite(fn func(conn net.Conn) func([]byte) (int, error)) *Conn

WithWrite overrides the Write method on the Conn

func (*Conn) Write

func (c *Conn) Write(b []byte) (n int, err error)

Write runs the Write method on the conn

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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