account_json.go 636 B

123456789101112131415161718192021222324252627282930313233343536
  1. // +build json
  2. package protocol
  3. import (
  4. "errors"
  5. "github.com/v2ray/v2ray-core/common/uuid"
  6. )
  7. type AccountJson struct {
  8. ID string `json:"id"`
  9. AlterIds uint16 `json:"alterId"`
  10. Username string `json:"user"`
  11. Password string `json:"pass"`
  12. }
  13. func (this *AccountJson) GetAccount() (Account, error) {
  14. if len(this.ID) > 0 {
  15. id, err := uuid.ParseString(this.ID)
  16. if err != nil {
  17. return nil, err
  18. }
  19. primaryID := NewID(id)
  20. alterIDs := NewAlterIDs(primaryID, this.AlterIds)
  21. return &VMessAccount{
  22. ID: primaryID,
  23. AlterIDs: alterIDs,
  24. }, nil
  25. }
  26. return nil, errors.New("Protocol: Malformed account.")
  27. }