in_user.go 802 B

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