nets

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package nets provides some assistant tools about net.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConnContextKey is a context key, which is used to access the connection.
	ConnContextKey = &contextKey{"conn"}

	// ListenerContextKey is a context key, which is used to access the listener.
	ListenerContextKey = &contextKey{"listener"}
)

Functions

func GetConnFromContext

func GetConnFromContext(ctx context.Context) net.Conn

GetConnFromContext extracts the net.Conn from the context with the key ConnContextKey.

Return nil if the value does not exist or is not of type net.Conn.

func GetListenerFromContext

func GetListenerFromContext(ctx context.Context) net.Listener

GetListenerFromContext extracts the net.Listener from the context with the key ListenerContextKey.

Return nil if the value does not exist or is not of type net.Listener.

func SetConnIntoContext

func SetConnIntoContext(parent context.Context, conn net.Conn) context.Context

SetConnIntoContext returns a new context with the key ConnContextKey and value conn.

func SetListenerIntoContext

func SetListenerIntoContext(parent context.Context, ln net.Listener) context.Context

SetListenerIntoContext returns a new context with the key ListenerContextKey and value ln.

Types

type IPChecker

type IPChecker struct{ netip.Prefix }

IPChecker is used to check whether an ip is contained.

func NewIPChecker

func NewIPChecker(cidr string) (c IPChecker, err error)

NewIPChecker returns a new ip checker.

func (IPChecker) ContainsAddr

func (c IPChecker) ContainsAddr(ip netip.Addr) bool

ContainsAddr reports whether the checker contains the ip addr.

func (IPChecker) ContainsIP

func (c IPChecker) ContainsIP(ip net.IP) bool

ContainsIP reports whether the checker contains the ip.

func (IPChecker) ContainsString

func (c IPChecker) ContainsString(ip string) bool

ContainsString reports whether the checker contains the ip string.

func (IPChecker) String

func (c IPChecker) String() string

String returns the description of the ip checker.

type IPCheckers

type IPCheckers []IPChecker

IPCheckers is a set of ip checkers.

func NewIPCheckers

func NewIPCheckers(cidrs ...string) (cs IPCheckers, err error)

NewIPCheckers returns a new ip checkers.

func (IPCheckers) ContainsAddr

func (cs IPCheckers) ContainsAddr(ip netip.Addr) bool

ContainsAddr reports whether the checkers contains the ip addr.

func (IPCheckers) ContainsIP

func (cs IPCheckers) ContainsIP(ip net.IP) bool

ContainsIP reports whether the checkers contains the ip.

func (IPCheckers) ContainsString

func (cs IPCheckers) ContainsString(ip string) bool

ContainsString reports whether the checkers contains the ip string.

func (IPCheckers) String

func (cs IPCheckers) String() string

String returns the description of the ip checkers.

Jump to

Keyboard shortcuts

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