config.go 579 B

123456789101112131415161718192021222324252627282930313233
  1. package rules
  2. import (
  3. v2net "github.com/v2ray/v2ray-core/common/net"
  4. )
  5. type Rule struct {
  6. Tag string
  7. Condition Condition
  8. }
  9. func (this *Rule) Apply(dest v2net.Destination) bool {
  10. return this.Condition.Apply(dest)
  11. }
  12. type RouterRuleConfig struct {
  13. rules []*Rule
  14. }
  15. func NewRouterRuleConfig() *RouterRuleConfig {
  16. return &RouterRuleConfig{
  17. rules: make([]*Rule, 0, 16),
  18. }
  19. }
  20. func (this *RouterRuleConfig) Add(rule *Rule) *RouterRuleConfig {
  21. this.rules = append(this.rules, rule)
  22. return this
  23. }
  24. func (this *RouterRuleConfig) Rules() []*Rule {
  25. return this.rules
  26. }