counter

package
v0.1.83 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountReader added in v0.1.81

func CountReader(r io.Reader, c *Counter) io.Reader

CountReader creates an io.Reader that counts bytes read from r, using the provided Counter.

func CountWriter added in v0.1.81

func CountWriter(w io.Writer, c *Counter) io.Writer

CountWriter creates an io.Writer that counts bytes written to w, using the provided Counter.

Types

type Counter

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

Counter is a thread-safe utility for counting values, starting from zero.

func (*Counter) Add

func (c *Counter) Add(delta int64) int64

Add adds delta to the Counter and returns the new value.

func (*Counter) Get added in v0.1.81

func (c *Counter) Get() int64

Get returns the current value of the Counter.

type CounterReader added in v0.1.81

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

CounterReader wraps an io.Reader to count the number of bytes read.

func NewCounterReader added in v0.1.81

func NewCounterReader(r io.Reader, c *Counter) *CounterReader

NewCounterReader creates a CounterReader that counts bytes read from r, using the provided Counter. If c is nil, a new Counter is created.

func (*CounterReader) Bytes added in v0.1.81

func (r *CounterReader) Bytes() int64

Bytes returns the total number of bytes read.

func (*CounterReader) Read added in v0.1.81

func (r *CounterReader) Read(p []byte) (n int, err error)

Read reads from the underlying Reader and increments the counter by the number of bytes read. It returns the number of bytes read and any error encountered.

type CounterWriter added in v0.1.81

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

CounterWriter wraps an io.Writer to count the number of bytes written.

func NewCounterWriter added in v0.1.81

func NewCounterWriter(w io.Writer, c *Counter) *CounterWriter

NewCounterWriter creates a CounterWriter that counts bytes written to w, using the provided Counter. If c is nil, a new Counter is created.

func (*CounterWriter) Bytes added in v0.1.81

func (w *CounterWriter) Bytes() int64

Bytes returns the total number of bytes written.

func (*CounterWriter) Write added in v0.1.81

func (w *CounterWriter) Write(p []byte) (n int, err error)

Write writes to the underlying Writer and increments the counter by the number of bytes written. It returns the number of bytes written and any error encountered.

type Listener

type Listener struct {
	net.Listener
	// contains filtered or unexported fields
}

Listener wraps a net.Listener to count bytes read and written across all connections.

func NewListener

func NewListener(listener net.Listener) *Listener

NewListener creates a Listener that counts bytes read and written across all connections.

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept accepts a connection and wraps it with byte counting for reads and writes. It returns the wrapped connection or an error if the accept fails.

func (*Listener) ReadBytes added in v0.1.81

func (l *Listener) ReadBytes() int64

ReadBytes returns the total number of bytes read across all connections.

func (*Listener) WriteBytes added in v0.1.81

func (l *Listener) WriteBytes() int64

WriteBytes returns the total number of bytes written across all connections.

Jump to

Keyboard shortcuts

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