1
0
mirror of https://github.com/MetaCubeX/mihomo.git synced 2025-07-18 17:08:06 +08:00
Files
mihomo/rules/common/in_user.go
wwqgtxx 5b975275f5 fix: incorrect checking of strings.Split return value
strings.Split will never return a slice of length 0 if sep is not empty, so any code that checks if the return value is of length 0 is incorrect and useless.
2025-06-25 16:20:37 +08:00

55 lines
915 B
Go

package common
import (
"fmt"
"strings"
C "github.com/metacubex/mihomo/constant"
)
type InUser struct {
*Base
users []string
adapter string
payload string
}
func (u *InUser) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
for _, user := range u.users {
if metadata.InUser == user {
return true, u.adapter
}
}
return false, ""
}
func (u *InUser) RuleType() C.RuleType {
return C.InUser
}
func (u *InUser) Adapter() string {
return u.adapter
}
func (u *InUser) Payload() string {
return u.payload
}
func NewInUser(iUsers, adapter string) (*InUser, error) {
users := strings.Split(iUsers, "/")
for i, user := range users {
user = strings.TrimSpace(user)
if len(user) == 0 {
return nil, fmt.Errorf("in user couldn't be empty")
}
users[i] = user
}
return &InUser{
Base: &Base{},
users: users,
adapter: adapter,
payload: iUsers,
}, nil
}