ip

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter IP 过滤器主结构体,用于控制 IP 访问权限

func New

func New(opts Options) *Filter

New 创建一个新的 IP 过滤器实例

func (*Filter) AllowIP

func (f *Filter) AllowIP(str string) bool

AllowIP 允许指定的 IP 地址或子网访问

func (*Filter) Allowed

func (f *Filter) Allowed(ip string) bool

Allowed 检查给定 IP 字符串是否被允许访问

func (*Filter) BlockIP

func (f *Filter) BlockIP(str string) bool

BlockIP 阻止指定的 IP 地址或子网访问

func (*Filter) Blocked

func (f *Filter) Blocked(ip string) bool

Blocked 检查给定 IP 字符串是否被阻止访问(与 Allowed 相反)

func (*Filter) NetAllowed

func (f *Filter) NetAllowed(ip net.IP) bool

NetAllowed 检查给定 net.IP 是否被允许访问

func (*Filter) NetBlocked

func (f *Filter) NetBlocked(ip net.IP) bool

NetBlocked 检查给定 net.IP 是否被阻止访问(与 NetAllowed 相反)

func (*Filter) ToggleDefault

func (f *Filter) ToggleDefault(allow bool)

ToggleDefault 修改默认访问策略

func (*Filter) ToggleIP

func (f *Filter) ToggleIP(str string, allowed bool) bool

ToggleIP 设置指定 IP 或子网的访问权限

type Options

type Options struct {
	// AllowedIps 允许访问的 IP 地址列表,支持单个 IP 或 CIDR 格式
	AllowedIps []string
	// BlockedIPs 被阻止的 IP 地址列表,支持单个 IP 或 CIDR 格式
	BlockedIPs []string

	// BlockByDefault 默认策略,true 表示默认拒绝所有,false 表示默认允许所有
	BlockByDefault bool
}

Options 配置选项结构体,用于初始化 IP 过滤器

Jump to

Keyboard shortcuts

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