github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/route/rule_item_clash_mode.go (about)

     1  package route
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/inazumav/sing-box/adapter"
     7  )
     8  
     9  var _ RuleItem = (*ClashModeItem)(nil)
    10  
    11  type ClashModeItem struct {
    12  	router adapter.Router
    13  	mode   string
    14  }
    15  
    16  func NewClashModeItem(router adapter.Router, mode string) *ClashModeItem {
    17  	return &ClashModeItem{
    18  		router: router,
    19  		mode:   mode,
    20  	}
    21  }
    22  
    23  func (r *ClashModeItem) Match(metadata *adapter.InboundContext) bool {
    24  	clashServer := r.router.ClashServer()
    25  	if clashServer == nil {
    26  		return false
    27  	}
    28  	return strings.EqualFold(clashServer.Mode(), r.mode)
    29  }
    30  
    31  func (r *ClashModeItem) String() string {
    32  	return "clash_mode=" + r.mode
    33  }