user.go 859 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package json
  2. import (
  3. "encoding/json"
  4. "github.com/v2ray/v2ray-core/proxy/vmess/config"
  5. )
  6. // ConfigUser is an user account in VMess configuration.
  7. type ConfigUser struct {
  8. Id *config.ID
  9. Email string
  10. LevelValue config.UserLevel
  11. }
  12. func (u *ConfigUser) UnmarshalJSON(data []byte) error {
  13. type rawUser struct {
  14. IdString string `json:"id"`
  15. EmailString string `json:"email"`
  16. LevelInt int `json:"level"`
  17. }
  18. var rawUserValue rawUser
  19. if err := json.Unmarshal(data, &rawUserValue); err != nil {
  20. return err
  21. }
  22. id, err := config.NewID(rawUserValue.IdString)
  23. if err != nil {
  24. return err
  25. }
  26. u.Id = id
  27. u.Email = rawUserValue.EmailString
  28. u.LevelValue = config.UserLevel(rawUserValue.LevelInt)
  29. return nil
  30. }
  31. func (u *ConfigUser) ID() *config.ID {
  32. return u.Id
  33. }
  34. func (this *ConfigUser) Level() config.UserLevel {
  35. return this.LevelValue
  36. }