Documentation ¶
Overview ¶
Package nets provides some assistant tools about net.
Index ¶
- Variables
- func GetConnFromContext(ctx context.Context) net.Conn
- func GetListenerFromContext(ctx context.Context) net.Listener
- func SetConnIntoContext(parent context.Context, conn net.Conn) context.Context
- func SetListenerIntoContext(parent context.Context, ln net.Listener) context.Context
- type IPChecker
- type IPCheckers
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
SetConnIntoContext returns a new context with the key ConnContextKey and value conn.
Types ¶
type IPChecker ¶
IPChecker is used to check whether an ip is contained.
func NewIPChecker ¶
NewIPChecker returns a new ip checker.
func (IPChecker) ContainsAddr ¶
ContainsAddr reports whether the checker contains the ip addr.
func (IPChecker) ContainsIP ¶
ContainsIP reports whether the checker contains the ip.
func (IPChecker) ContainsString ¶
ContainsString reports whether the checker contains the ip string.
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.