- 添加 convertToReverseConfig 函数,将 config.Config 转换为 reverse.Config - 修正配置字段映射关系: - EnableHTTPS -> DecryptHTTPS - EnableWebSocket -> SupportWebSocketUpgrade - 保持其他配置字段映射不变 - 优化代码格式和注释 BREAKING CHANGE: 反向代理配置结构发生变化,需要更新相关配置
101 lines
2.1 KiB
Go
101 lines
2.1 KiB
Go
package rule
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// RuleType 规则类型
|
|
type RuleType string
|
|
|
|
const (
|
|
// RuleTypeDNS DNS规则类型
|
|
RuleTypeDNS RuleType = "dns"
|
|
// RuleTypeRewrite URL重写规则类型
|
|
RuleTypeRewrite RuleType = "rewrite"
|
|
// RuleTypeRoute 路由规则类型
|
|
RuleTypeRoute RuleType = "route"
|
|
)
|
|
|
|
// MatchType 匹配类型
|
|
type MatchType string
|
|
|
|
const (
|
|
// MatchTypeExact 精确匹配
|
|
MatchTypeExact MatchType = "exact"
|
|
// MatchTypeWildcard 通配符匹配
|
|
MatchTypeWildcard MatchType = "wildcard"
|
|
// MatchTypeRegex 正则匹配
|
|
MatchTypeRegex MatchType = "regex"
|
|
// MatchTypePath 路径匹配
|
|
MatchTypePath MatchType = "path"
|
|
)
|
|
|
|
// Rule 统一的规则接口
|
|
type Rule interface {
|
|
// GetID 获取规则ID
|
|
GetID() string
|
|
// GetType 获取规则类型
|
|
GetType() RuleType
|
|
// GetPriority 获取规则优先级
|
|
GetPriority() int
|
|
// Match 匹配规则
|
|
Match(req *http.Request) bool
|
|
// Apply 应用规则
|
|
Apply(req *http.Request) error
|
|
// Validate 验证规则
|
|
Validate() error
|
|
}
|
|
|
|
// BaseRule 基础规则结构
|
|
type BaseRule struct {
|
|
ID string `json:"id"`
|
|
Type RuleType `json:"type"`
|
|
Priority int `json:"priority"`
|
|
Pattern string `json:"pattern"`
|
|
MatchType MatchType `json:"match_type"`
|
|
Enabled bool `json:"enabled"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// DNSRule DNS规则
|
|
type DNSRule struct {
|
|
BaseRule
|
|
Targets []DNSTarget `json:"targets"`
|
|
}
|
|
|
|
// DNSTarget DNS目标
|
|
type DNSTarget struct {
|
|
IP string `json:"ip"`
|
|
Port int `json:"port"`
|
|
}
|
|
|
|
// RewriteRule URL重写规则
|
|
type RewriteRule struct {
|
|
BaseRule
|
|
Replacement string `json:"replacement"`
|
|
}
|
|
|
|
// RouteRule 路由规则
|
|
type RouteRule struct {
|
|
BaseRule
|
|
Target string `json:"target"`
|
|
HeaderModifier map[string]string `json:"header_modifier"`
|
|
}
|
|
|
|
// GetID 获取规则ID
|
|
func (r *BaseRule) GetID() string {
|
|
return r.ID
|
|
}
|
|
|
|
// GetType 获取规则类型
|
|
func (r *BaseRule) GetType() RuleType {
|
|
return r.Type
|
|
}
|
|
|
|
// GetPriority 获取规则优先级
|
|
func (r *BaseRule) GetPriority() int {
|
|
return r.Priority
|
|
}
|