router

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action定义流量走向

const (
	ActionProxy  Action = "PROXY"  // 走代理
	ActionDirect Action = "DIRECT" // 直连
	ActionReject Action = "REJECT" // 拒绝
)

type Mode

type Mode string

Mode定义全局路由的模式

const (
	ModeRule   Mode = "rule"   // 规则模式
	ModeDirect Mode = "direct" // 全局直连
	ModeGlobal Mode = "global" // 全局代理
)

type Router

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

Router 路由的核心结构体

func NewRouter

func NewRouter(path string) (*Router, error)

从指定YAML文件路径中创建并初始化一个新的Router

func (*Router) Match

func (r *Router) Match(host string) Action

根据主机名决定流量的走向

type Rule

type Rule struct {
	Type    RuleType
	Payload string // ip或者域名(具体的待匹配值)
	Target  Action // 动作
}

Rule 代表一条路由规则

type RuleType

type RuleType string

定义规则类型

const (
	DomainSuffix  RuleType = "DOMAIN-SUFFIX"  // 域名后缀匹配
	DomainKeyword RuleType = "DOMAIN-KEYWORD" // 域名关键字匹配
	Domain        RuleType = "DOMAIN"         // 完整域名匹配
	IPCIDR        RuleType = "IP-CIDR"        // IP段匹配
	IPCIDR6       RuleType = "IP-CIDR6"       // IPv6
	Match         RuleType = "MATCH"          // 所有规则都没命中时的匹配
)

Jump to

Keyboard shortcuts

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