netip

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package netip provides wrappers around net/netip types to implement the flag.Value interface. This allows these types to be used with the Go flag package for command-line flag parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidIPv4 added in v0.26.0

func ValidIPv4(addr netip.Addr) error

ValidIPv4 reports an error when addr is not IPv4. IPv4-mapped IPv6 addresses such as ::ffff:192.0.2.1 are rejected by both this and ValidIPv6: they are ambiguous in exactly the way family-scoped flags exist to disambiguate.

func ValidIPv6 added in v0.26.0

func ValidIPv6(addr netip.Addr) error

ValidIPv6 reports an error when addr is not IPv6.

Types

type Addr

type Addr struct {
	*netip.Addr
	// contains filtered or unexported fields
}

Addr wraps a netip.Addr to implement the flag.Value interface. It represents an IP address without a port.

func (*Addr) RequireIPv4 added in v0.26.0

func (a *Addr) RequireIPv4()

RequireIPv4 implements FamilyRestricter.

func (*Addr) RequireIPv6 added in v0.26.0

func (a *Addr) RequireIPv6()

RequireIPv6 implements FamilyRestricter.

func (*Addr) Reset

func (a *Addr) Reset() error

Reset sets the Addr to its zero value. Returns an error if the Addr is nil.

func (*Addr) Set

func (a *Addr) Set(s string) error

Set implements the flag.Value interface. Parses a string as an IP address and sets the Addr value. Returns an error if the string cannot be parsed or if the Addr is nil. An empty input string is treated as a no-op and returns nil.

func (*Addr) String added in v0.22.0

func (a *Addr) String() string

String returns the string representation of the Addr. Returns an empty string if the Addr is nil or invalid.

func (*Addr) Type

func (a *Addr) Type() string

Type implements the flag.Value interface. Returns the type of the flag as a string.

type AddrPort

type AddrPort struct{ *netip.AddrPort }

AddrPort wraps a netip.AddrPort to implement the flag.Value interface. It represents an IP address and port number.

func (*AddrPort) Reset

func (a *AddrPort) Reset() error

Reset sets the AddrPort to its zero value. Returns an error if the AddrPort is nil.

func (*AddrPort) Set

func (a *AddrPort) Set(s string) error

Set implements the flag.Value interface. Parses a string in the format "ip:port" and sets the AddrPort value. Returns an error if the string cannot be parsed or if the AddrPort is nil. An empty input string is treated as a no-op and returns nil.

func (*AddrPort) String added in v0.22.0

func (a *AddrPort) String() string

String returns the string representation of the AddrPort. Returns an empty string if the AddrPort is nil or invalid.

func (*AddrPort) Type

func (a *AddrPort) Type() string

Type implements the flag.Value interface. Returns the type of the flag as a string.

type FamilyRestricter added in v0.26.0

type FamilyRestricter interface {
	RequireIPv4()
	RequireIPv6()
}

FamilyRestricter is implemented by flag values that accept a single IP address family. Registering a flag under a family name calls it so the name and the accepted family cannot disagree.

type Prefix

type Prefix struct {
	*netip.Prefix
	// contains filtered or unexported fields
}

Prefix wraps a netip.Prefix to implement the flag.Value interface. It represents an IP network with address and mask (CIDR notation).

func (*Prefix) RequireIPv4 added in v0.26.0

func (p *Prefix) RequireIPv4()

RequireIPv4 implements FamilyRestricter.

func (*Prefix) RequireIPv6 added in v0.26.0

func (p *Prefix) RequireIPv6()

RequireIPv6 implements FamilyRestricter.

func (*Prefix) Reset added in v0.22.0

func (p *Prefix) Reset() error

Reset sets the Prefix to its zero value.

func (*Prefix) Set

func (p *Prefix) Set(s string) error

Set implements the flag.Value interface. Parses a string in CIDR notation (e.g., "192.168.0.0/24") and sets the Prefix value. Returns an error if the string cannot be parsed or if the Prefix is nil. An empty input string is treated as a no-op and returns nil.

func (*Prefix) String added in v0.22.0

func (p *Prefix) String() string

String returns the string representation of the Prefix. Returns an empty string if the Prefix is nil or invalid.

func (*Prefix) Type

func (p *Prefix) Type() string

Type implements the flag.Value interface. Returns the type of the flag as a string.

type PrefixList

type PrefixList struct {
	PrefixList *[]netip.Prefix
}

PrefixList wraps a slice of netip.Prefix to implement the flag.Value interface. It represents a list of IP networks specified in CIDR notation.

func ToPrefixList

func ToPrefixList(p *[]netip.Prefix) *PrefixList

ToPrefixList creates a new PrefixList wrapper around a slice of netip.Prefix. This is a helper function to easily create a PrefixList from an existing slice.

func (*PrefixList) Reset

func (p *PrefixList) Reset() error

Reset sets the PrefixList to nil. Returns an error if the PrefixList is nil.

func (*PrefixList) Set

func (p *PrefixList) Set(s string) error

Set implements the flag.Value interface. Parses a comma-separated string of CIDR notations and sets the PrefixList value. Returns an error if any prefix cannot be parsed or if the PrefixList is nil. An empty input string is treated as a no-op and returns nil.

func (*PrefixList) Slice

func (p *PrefixList) Slice() []string

Slice returns a slice of strings representing each prefix. Returns nil if the PrefixList is nil.

func (*PrefixList) String

func (p *PrefixList) String() string

String returns a comma-separated string of all prefixes. Returns an empty string if the PrefixList is nil.

func (*PrefixList) Type

func (p *PrefixList) Type() string

Type implements the flag.Value interface. Returns the type of the flag as a string.

Jump to

Keyboard shortcuts

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