github.com/metacubex/mihomo@v1.18.5/rules/common/in_user.go (about) 1 package common 2 3 import ( 4 "fmt" 5 C "github.com/metacubex/mihomo/constant" 6 "strings" 7 ) 8 9 type InUser struct { 10 *Base 11 users []string 12 adapter string 13 payload string 14 } 15 16 func (u *InUser) Match(metadata *C.Metadata) (bool, string) { 17 for _, user := range u.users { 18 if metadata.InUser == user { 19 return true, u.adapter 20 } 21 } 22 return false, "" 23 } 24 25 func (u *InUser) RuleType() C.RuleType { 26 return C.InUser 27 } 28 29 func (u *InUser) Adapter() string { 30 return u.adapter 31 } 32 33 func (u *InUser) Payload() string { 34 return u.payload 35 } 36 37 func NewInUser(iUsers, adapter string) (*InUser, error) { 38 users := strings.Split(iUsers, "/") 39 if len(users) == 0 { 40 return nil, fmt.Errorf("in user couldn't be empty") 41 } 42 43 return &InUser{ 44 Base: &Base{}, 45 users: users, 46 adapter: adapter, 47 payload: iUsers, 48 }, nil 49 }