pkg

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsurePrefix

func EnsurePrefix(s string) string

If the string does end with an explicit subnet mask, then append '/32'

func LineParser added in v0.2.0

func LineParser(
	fields []int,
	delimiter string,
	valParser func(string) (netip.Prefix, error),
) func(string) ([]netip.Prefix, error)

LineParser returns a function that parses a line into a slice of prefixes.

func LoadPrefixSetBuilderFromFile

func LoadPrefixSetBuilderFromFile(
	path string,
	errFn func(string, error) error,
) (*netipds.PrefixSetBuilder, error)

func LoadPrefixSetFromFile

func LoadPrefixSetFromFile(
	path string,
	errFn func(string, error) error,
) (*netipds.PrefixSet, error)

func ParseHost added in v0.2.0

func ParseHost(s string) (netip.Prefix, error)

ParseHost parses a string as an IP with an optional :port suffix and returns the IP as a netip.Prefix.

func ParsePrefixOrAddr

func ParsePrefixOrAddr(s string) (netip.Prefix, error)

ParsePrefixOrAddr parses a string as a CIDR prefix or an IP address.

func ParseUrl added in v0.2.0

func ParseUrl(s string) (netip.Prefix, error)

ParseUrl parses a string as a URL and returns the host as a netip.Prefix. If the URL is invalid, an error is returned. If the host is not an IP address, an error is returned.

func StrSliceToPrefixSlice

func StrSliceToPrefixSlice(cidrStrs []string) ([]netip.Prefix, error)

StrSliceToPrefixSlice converts a slice of CIDR strings to a slice of Prefixes.

func StringMaybeAddr added in v0.2.0

func StringMaybeAddr(p netip.Prefix) string

StringMaybeAddr returns the Prefix as a string, stripping the prefix length if the Prefix is a single IP.

func ToSliceOfOneFn added in v0.2.0

func ToSliceOfOneFn[A, B any](fn func(A) (B, error)) func(A) ([]B, error)

ToSliceOfOneFn converts a function that returns a single value and an error into a function that returns a slice of one value and an error.

func ValParser added in v0.2.0

func ValParser(acceptUrl bool, acceptHostPort bool) func(string) (netip.Prefix, error)

Types

type CidrProcessor

type CidrProcessor struct {
	Fields    []int
	Delimiter string
	ValParser func(string) (netip.Prefix, error)
	HandlerFn func(*ParsedLine) error
	ErrFn     func(string, error) error
}

CidrProcessor consolidates all of the configuration provided by a user for processing lists of CIDRs.

func (*CidrProcessor) Process

func (p *CidrProcessor) Process(r io.Reader) error

Process parses all lines from the provided reader and calls p.HandlerFn on each parsed line, handling errors with p.ErrFn.

type ParsedLine added in v0.2.0

type ParsedLine struct {
	Raw string

	Prefixes []netip.Prefix
	// contains filtered or unexported fields
}

func (*ParsedLine) Clean added in v0.2.0

func (p *ParsedLine) Clean() string

Clean returns the raw line with any parsed fields replaced by their extracted Prefixes.

Jump to

Keyboard shortcuts

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