You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

34 rivejä
752 B

  1. package common
  2. import "errors"
  3. const (
  4. ForeignUserIDStart = 10000000
  5. UserSourceLocal = "local"
  6. UserSourceSynced = "synced"
  7. )
  8. func IsSyncedUser(source string, id int) bool {
  9. return source == UserSourceSynced && id > 0 && id < ForeignUserIDStart
  10. }
  11. func IsLocalUser(source string, id int) bool {
  12. if source == UserSourceLocal {
  13. return true
  14. }
  15. if id >= ForeignUserIDStart {
  16. return true
  17. }
  18. return false
  19. }
  20. func ValidateUserSource(source string, id int) error {
  21. if source == UserSourceSynced && id >= ForeignUserIDStart {
  22. return errors.New("synced 用户 ID 必须小于 1千万")
  23. }
  24. if source == UserSourceLocal && id > 0 && id < ForeignUserIDStart {
  25. return errors.New("local 用户 ID 必须大于等于 1千万")
  26. }
  27. return nil
  28. }