当前位置:   article > 正文

go生成唯一id(uuid)_go 唯一id

go 唯一id
  1. # UUID package for Go language
  2. [![Build Status](https://travis-ci.org/satori/go.uuid.svg?branch=master)](https://travis-ci.org/satori/go.uuid)
  3. [![Coverage Status](https://coveralls.io/repos/github/satori/go.uuid/badge.svg?branch=master)](https://coveralls.io/github/satori/go.uuid)
  4. [![GoDoc](http://godoc.org/github.com/satori/go.uuid?status.svg)](http://godoc.org/github.com/satori/go.uuid)
  5. This package provides pure Go implementation of Universally Unique Identifier (UUID). Supported both creation and parsing of UUIDs.
  6. With 100% test coverage and benchmarks out of box.
  7. Supported versions:
  8. * Version 1, based on timestamp and MAC address (RFC 4122)
  9. * Version 2, based on timestamp, MAC address and POSIX UID/GID (DCE 1.1)
  10. * Version 3, based on MD5 hashing (RFC 4122)
  11. * Version 4, based on random numbers (RFC 4122)
  12. * Version 5, based on SHA-1 hashing (RFC 4122)
  13. ## Installation
  14. Use the `go` command:
  15. $ go get github.com/satori/go.uuid
  16. ## Requirements
  17. UUID package tested against Go >= 1.6.
  18. ## Example
  19. ```go
  20. package main
  21. import (
  22. "fmt"
  23. "github.com/satori/go.uuid"
  24. )
  25. func main() {
  26. // Creating UUID Version 4
  27. // panic on error
  28. u1 := uuid.Must(uuid.NewV4())
  29. fmt.Printf("UUIDv4: %s\n", u1)
  30. // or error handling
  31. u2, err := uuid.NewV4()
  32. if err != nil {
  33. fmt.Printf("Something went wrong: %s", err)
  34. return
  35. }
  36. fmt.Printf("UUIDv4: %s\n", u2)
  37. // Parsing UUID from string input
  38. u2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
  39. if err != nil {
  40. fmt.Printf("Something went wrong: %s", err)
  41. return
  42. }
  43. fmt.Printf("Successfully parsed: %s", u2)
  44. }
  45. ```
  46. ## Documentation
  47. [Documentation](http://godoc.org/github.com/satori/go.uuid) is hosted at GoDoc project.
  48. ## Links
  49. * [RFC 4122](http://tools.ietf.org/html/rfc4122)
  50. * [DCE 1.1: Authentication and Security Services](http://pubs.opengroup.org/onlinepubs/9696989899/chap5.htm#tagcjh_08_02_01_01)
  51. ## Copyright
  52. Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>.
  53. UUID package released under MIT License.
  54. See [LICENSE](https://github.com/satori/go.uuid/blob/master/LICENSE) for details.

参考资料  go生成uuid

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/850938
推荐阅读
相关标签
  

闽ICP备14008679号