restr

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IP

type IP struct {
	Allows []netip.Prefix `json:"allows,omitempty"`
	Denies []netip.Prefix `json:"denies,omitempty"`
}

func ParseIP

func ParseIP(allowsStr []string, deniesStr []string) (IP, error)

ParseIP parses a slice of allows/denys restrictions in CIDR format.

func (IP) IsAllowed

func (r IP) IsAllowed(ip netip.Addr) bool

IsAllowed checks if an IP address is allowed according to Allows and Denies rules.

If the ip matches any of the Denies rules, IsAllowed returns false. If the ip matches any of the Allows rules (after checking all Denies rules), IsAllowed returns true.

Finally, if the ip matches no Allows or Denies rules, IsAllowed returns true only if no explicit Allows rules were defined.

func (IP) IsAllowedAddr

func (r IP) IsAllowedAddr(addr net.Addr) bool

IsAllowedAddr extracts the IP address from net.Addr and checks if it is allowed

func (IP) IsEmpty

func (r IP) IsEmpty() bool

func (IP) IsNotEmpty

func (r IP) IsNotEmpty() bool

type Name

type Name struct {
	Expression *regexp.Regexp `json:"expression,omitempty"`
}

func ParseName

func ParseName(s string) (Name, error)

func (Name) IsAllowed

func (r Name) IsAllowed(s string) bool

Jump to

Keyboard shortcuts

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