version.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package uuid
  2. import (
  3. "github.com/golang-plus/uuid/internal"
  4. )
  5. // Version represents the version of UUID. See page 7 in RFC 4122.
  6. type Version byte
  7. // Versions.
  8. const (
  9. // VersionUnknown represents unknown version.
  10. VersionUnknown = Version(internal.VersionUnknown)
  11. // VersionTimeBased represents the time-based version (Version 1).
  12. VersionTimeBased = Version(internal.VersionTimeBased)
  13. // VersionDCESecurity represents the DCE security version, with embedded POSIX UIDs (Version 2).
  14. VersionDCESecurity = Version(internal.VersionDCESecurity)
  15. // VersionNameBasedMD5 represents the name-based version that uses MD5 hashing (Version 3).
  16. VersionNameBasedMD5 = Version(internal.VersionNameBasedMD5)
  17. // VersionRandom represents the randomly or pseudo-randomly generated version (Version 4).
  18. VersionRandom = Version(internal.VersionRandom)
  19. // VersionNameBasedSHA1 represents the name-based version that uses SHA-1 hashing (Version 5).
  20. VersionNameBasedSHA1 = Version(internal.VersionNameBasedSHA1)
  21. )
  22. // Short names of versions.
  23. const (
  24. V1 = VersionTimeBased
  25. V2 = VersionDCESecurity
  26. V3 = VersionNameBasedMD5
  27. V4 = VersionRandom
  28. V5 = VersionNameBasedSHA1
  29. )
  30. // String returns English description of Version.
  31. func (v Version) String() string {
  32. switch v {
  33. case VersionTimeBased:
  34. return "Version 1: Time-Based"
  35. case VersionDCESecurity:
  36. return "Version 2: DCE Security With Embedded POSIX UIDs"
  37. case VersionNameBasedMD5:
  38. return "Version 3: Name-Based (MD5)"
  39. case VersionRandom:
  40. return "Version 4: Randomly OR Pseudo-Randomly Generated"
  41. case VersionNameBasedSHA1:
  42. return "Version 5: Name-Based (SHA-1)"
  43. default:
  44. return "Version: Unknwon"
  45. }
  46. }