account_json.go 667 B

12345678910111213141516171819202122232425262728293031
  1. // +build json
  2. package vmess
  3. import (
  4. "encoding/json"
  5. "github.com/v2ray/v2ray-core/common/log"
  6. "github.com/v2ray/v2ray-core/common/protocol"
  7. "github.com/v2ray/v2ray-core/common/uuid"
  8. )
  9. func (u *Account) UnmarshalJSON(data []byte) error {
  10. type JsonConfig struct {
  11. ID string `json:"id"`
  12. AlterIds uint16 `json:"alterId"`
  13. }
  14. var rawConfig JsonConfig
  15. if err := json.Unmarshal(data, &rawConfig); err != nil {
  16. return err
  17. }
  18. id, err := uuid.ParseString(rawConfig.ID)
  19. if err != nil {
  20. log.Error("VMess: Failed to parse ID: ", err)
  21. return err
  22. }
  23. u.ID = protocol.NewID(id)
  24. u.AlterIDs = protocol.NewAlterIDs(u.ID, rawConfig.AlterIds)
  25. return nil
  26. }