netip

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: Apache-2.0 Imports: 3 Imported by: 2

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

This section is empty.

Types

type Addr

type Addr struct{ *netip.Addr }

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

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 Prefix

type Prefix struct{ *netip.Prefix }

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

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