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.

86 lines
2.8 KiB

  1. Go UUID implementation
  2. ========================
  3. [![Build Status](https://travis-ci.org/twinj/uuid.png?branch=master)](https://travis-ci.org/twinj/uuid)
  4. [![GoDoc](http://godoc.org/github.com/twinj/uuid?status.png)](http://godoc.org/github.com/twinj/uuid)
  5. This package provides RFC 4122 compliant UUIDs.
  6. It will generate the following:
  7. * Version 1: based on timestamp and MAC address
  8. * Version 3: based on MD5 hash
  9. * Version 4: based on cryptographically secure random numbers
  10. * Version 5: based on SHA-1 hash
  11. Functions NewV1, NewV3, NewV4, NewV5, New, NewHex and Parse() for generating versions 3, 4
  12. and 5 UUIDs are as specified in [RFC 4122](http://www.ietf.org/rfc/rfc4122.txt).
  13. # Requirements
  14. Go 1.4, 1.3, 1.2 and tip supported.
  15. # Recent Changes
  16. * Removed use of OS Thread locking and runtime package requirement
  17. * Changed String() output to CleanHyphen to match the canonical standard
  18. * Plenty of minor change and housekeeping
  19. * Removed default saver and replaced with interface
  20. * API changes to simplify use.
  21. * Added formatting support for user defined formats
  22. * Added support for Google App Engine
  23. * Variant type bits are now set correctly
  24. * Variant type can now be retrieved more efficiently
  25. * New tests for variant setting to confirm correctness
  26. * New tests added to confirm proper version setting
  27. * Type UUID change to UUIDArray for V3-5 UUIDs and UUIDStruct added for V1 UUIDs
  28. ** These implement the BinaryMarshaller and BinaryUnmarshaller interfaces
  29. * New was added to create a base UUID from a []byte slice - this uses UUIDArray
  30. * ParseHex was renamed to ParseUUID
  31. * NewHex now performs unsafe creation of UUID from a hex string
  32. * NewV3 and NewV5 now take anything that implements the Stringer interface
  33. * V1 UUIDs can now be created
  34. * The printing format can be changed
  35. ## Installation
  36. Use the `go` tool:
  37. $ go get github.com/twinj/uuid
  38. ## Usage
  39. See [documentation and examples](http://godoc.org/github.com/twinj/uuid)
  40. for more information.
  41. var config = uuid.StateSaverConfig{SaveReport: true, SaveSchedule: 30 * time.Minute}
  42. uuid.SetupFileSystemStateSaver(config)
  43. u1 := uuid.NewV1()
  44. uP, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
  45. u3 := uuid.NewV3(uP, uuid.Name("test"))
  46. u4 := uuid.NewV4()
  47. fmt.Printf(print, u4.Version(), u4.Variant(), u4)
  48. u5 := uuid.NewV5(uuid.NamespaceURL, uuid.Name("test"))
  49. if uuid.Equal(u1, u3) {
  50. fmt.Printf("Will never happen")
  51. }
  52. fmt.Printf(uuid.Formatter(u5, uuid.CurlyHyphen))
  53. uuid.SwitchFormat(uuid.BracketHyphen)
  54. ## Copyright
  55. This is a derivative work
  56. Orginal version from
  57. Copyright (C) 2011 by Krzysztof Kowalik <chris@nu7hat.ch>.
  58. See [COPYING](https://github.com/nu7hatch/gouuid/tree/master/COPYING)
  59. file for details.
  60. Also see: Algorithm details in [RFC 4122](http://www.ietf.org/rfc/rfc4122.txt).
  61. Copyright (C) 2014 twinj@github.com
  62. See [LICENSE](https://github.com/twinj/uuid/tree/master/LICENSE)
  63. file for details.