sing-box/route/rule_item_outbound.go

36 lines
768 B
Go
Raw Permalink Normal View History

2022-07-07 21:47:21 +08:00
package route
import (
"strings"
"github.com/sagernet/sing-box/adapter"
2022-07-08 23:03:57 +08:00
F "github.com/sagernet/sing/common/format"
2022-07-07 21:47:21 +08:00
)
var _ RuleItem = (*OutboundItem)(nil)
type OutboundItem struct {
outbounds []string
outboundMap map[string]bool
}
func NewOutboundRule(outbounds []string) *OutboundItem {
rule := &OutboundItem{outbounds, make(map[string]bool)}
for _, outbound := range outbounds {
rule.outboundMap[outbound] = true
}
return rule
}
func (r *OutboundItem) Match(metadata *adapter.InboundContext) bool {
return r.outboundMap[metadata.Outbound]
}
func (r *OutboundItem) String() string {
if len(r.outbounds) == 1 {
return F.ToString("outbound=", r.outbounds[0])
} else {
return F.ToString("outbound=[", strings.Join(r.outbounds, " "), "]")
}
}