netw

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package netw is a wrapper around network connections that stores annotations and records metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Listen

func Listen(network, laddr string) (net.Listener, error)

Listen creates a net listener that is instrumented to store per connection annotations and metrics.

func SetAnnotation

func SetAnnotation(conn net.Conn, key string, value any)

SetAnnotation sets an annotation on a connection. The value can be any go value.

Types

type Conn

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

Conn is a wrapper around net.Conn that stores annotations and metrics.

func (*Conn) Annotation

func (c *Conn) Annotation(key string, defaultValue any) any

Annotation retrieves an annotation that was previously set on the connection. The defaultValue is returned if the annotation was never set.

func (*Conn) BytesReceived

func (c *Conn) BytesReceived() int64

BytesReceived returns the number of bytes received on this connection so far.

func (*Conn) BytesSent

func (c *Conn) BytesSent() int64

BytesSent returns the number of bytes sent on this connection so far.

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) OnClose

func (c *Conn) OnClose(f func())

OnClose sets a callback function that will be called when the connection is closed.

func (*Conn) Peek

func (c *Conn) Peek(b []byte) (int, error)

func (*Conn) Read

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

func (*Conn) SetAnnotation

func (c *Conn) SetAnnotation(key string, value any)

SetAnnotation sets an annotation. The value can be any go value.

func (*Conn) Write

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

Jump to

Keyboard shortcuts

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