| 1 | Package uniuri |
| 2 | ===================== |
| 3 | |
| 4 | ```go |
| 5 | import "github.com/dchest/uniuri" |
| 6 | ``` |
| 7 | |
| 8 | Package uniuri generates random strings good for use in URIs to identify |
| 9 | unique objects. |
| 10 | |
| 11 | Example usage: |
| 12 | |
| 13 | ```go |
| 14 | s := uniuri.New() // s is now "apHCJBl7L1OmC57n" |
| 15 | ``` |
| 16 | |
| 17 | A standard string created by New() is 16 bytes in length and consists of |
| 18 | Latin upper and lowercase letters, and numbers (from the set of 62 allowed |
| 19 | characters), which means that it has ~95 bits of entropy. To get more |
| 20 | entropy, you can use NewLen(UUIDLen), which returns 20-byte string, giving |
| 21 | ~119 bits of entropy, or any other desired length. |
| 22 | |
| 23 | Functions read from crypto/rand random source, and panic if they fail to |
| 24 | read from it. |
| 25 | |
| 26 | |
| 27 | Constants |
| 28 | --------- |
| 29 | |
| 30 | ```go |
| 31 | const ( |
| 32 | // StdLen is a standard length of uniuri string to achive ~95 bits of entropy. |
| 33 | StdLen = 16 |
| 34 | // UUIDLen is a length of uniuri string to achive ~119 bits of entropy, closest |
| 35 | // to what can be losslessly converted to UUIDv4 (122 bits). |
| 36 | UUIDLen = 20 |
| 37 | ) |
| 38 | |
| 39 | ``` |
| 40 | |
| 41 | |
| 42 | |
| 43 | Variables |
| 44 | --------- |
| 45 | |
| 46 | ```go |
| 47 | var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |
| 48 | ``` |
| 49 | |
| 50 | |
| 51 | StdChars is a set of standard characters allowed in uniuri string. |
| 52 | |
| 53 | |
| 54 | Functions |
| 55 | --------- |
| 56 | |
| 57 | ### func New |
| 58 | |
| 59 | ```go |
| 60 | func New() string |
| 61 | ``` |
| 62 | |
| 63 | New returns a new random string of the standard length, consisting of |
| 64 | standard characters. |
| 65 | |
| 66 | ### func NewLen |
| 67 | |
| 68 | ```go |
| 69 | func NewLen(length int) string |
| 70 | ``` |
| 71 | |
| 72 | NewLen returns a new random string of the provided length, consisting of |
| 73 | standard characters. |
| 74 | |
| 75 | ### func NewLenChars |
| 76 | |
| 77 | ```go |
| 78 | func NewLenChars(length int, chars []byte) string |
| 79 | ``` |
| 80 | |
| 81 | NewLenChars returns a new random string of the provided length, consisting |
| 82 | of the provided byte slice of allowed characters (maximum 256). |
| 83 | |
| 84 | |
| 85 | |
| 86 | Public domain dedication |
| 87 | ------------------------ |
| 88 | |
| 89 | Written in 2011-2014 by Dmitry Chestnykh |
| 90 | |
| 91 | The author(s) have dedicated all copyright and related and |
| 92 | neighboring rights to this software to the public domain |
| 93 | worldwide. Distributed without any warranty. |
| 94 | http://creativecommons.org/publicdomain/zero/1.0/ |
| 95 |