mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-25 11:35:34 -05:00
simplify router config
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app/router"
|
||||
"github.com/v2ray/v2ray-core/app/router/rules/config"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
@@ -14,7 +13,18 @@ var (
|
||||
)
|
||||
|
||||
type Router struct {
|
||||
rules []config.Rule
|
||||
rules []Rule
|
||||
}
|
||||
|
||||
func NewRouter() *Router {
|
||||
return &Router{
|
||||
rules: make([]Rule, 0, 16),
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Router) AddRule(rule Rule) *Router {
|
||||
this.rules = append(this.rules, rule)
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *Router) TakeDetour(dest v2net.Destination) (string, error) {
|
||||
@@ -30,16 +40,16 @@ type RouterFactory struct {
|
||||
}
|
||||
|
||||
func (this *RouterFactory) Create(rawConfig interface{}) (router.Router, error) {
|
||||
config := rawConfig.(config.RouterRuleConfig)
|
||||
config := rawConfig.(RouterRuleConfig)
|
||||
rules := config.Rules()
|
||||
router := NewRouter()
|
||||
for _, rule := range rules {
|
||||
if rule == nil {
|
||||
return nil, InvalidRule
|
||||
}
|
||||
router.AddRule(rule)
|
||||
}
|
||||
return &Router{
|
||||
rules: rules,
|
||||
}, nil
|
||||
return router, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
Reference in New Issue
Block a user