2011-04-16 21:39:53 +02:00
|
|
|
Package uniuri
|
|
|
|
=====================
|
2011-04-05 17:57:25 +02:00
|
|
|
|
2013-12-12 18:04:03 +01:00
|
|
|
[![Build Status](https://travis-ci.org/dchest/uniuri.png)](https://travis-ci.org/dchest/uniuri)
|
|
|
|
|
2013-09-23 18:32:11 +02:00
|
|
|
```go
|
|
|
|
import "github.com/dchest/uniuri"
|
|
|
|
```
|
2011-04-05 17:57:25 +02:00
|
|
|
|
|
|
|
Package uniuri generates random strings good for use in URIs to identify
|
|
|
|
unique objects.
|
|
|
|
|
|
|
|
Example usage:
|
|
|
|
|
2013-09-23 18:32:11 +02:00
|
|
|
```go
|
|
|
|
s := uniuri.New() // s is now "apHCJBl7L1OmC57n"
|
|
|
|
```
|
2011-04-05 17:57:25 +02:00
|
|
|
|
|
|
|
A standard string created by New() is 16 bytes in length and consists of
|
|
|
|
Latin upper and lowercase letters, and numbers (from the set of 62 allowed
|
|
|
|
characters), which means that it has ~95 bits of entropy. To get more
|
|
|
|
entropy, you can use NewLen(UUIDLen), which returns 20-byte string, giving
|
|
|
|
~119 bits of entropy, or any other desired length.
|
|
|
|
|
|
|
|
Functions read from crypto/rand random source, and panic if they fail to
|
|
|
|
read from it.
|
|
|
|
|
|
|
|
|
2011-04-16 21:39:53 +02:00
|
|
|
Constants
|
|
|
|
---------
|
2011-04-05 17:57:25 +02:00
|
|
|
|
2013-09-23 18:32:11 +02:00
|
|
|
```go
|
|
|
|
const (
|
|
|
|
// Standard length of uniuri string to achive ~95 bits of entropy.
|
|
|
|
StdLen = 16
|
|
|
|
// Length of uniurl string to achive ~119 bits of entropy, closest
|
|
|
|
// to what can be losslessly converted to UUIDv4 (122 bits).
|
|
|
|
UUIDLen = 20
|
|
|
|
)
|
|
|
|
```
|
2011-04-05 17:57:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-16 21:39:53 +02:00
|
|
|
Variables
|
|
|
|
---------
|
|
|
|
|
2013-09-23 18:32:11 +02:00
|
|
|
```go
|
|
|
|
var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
|
|
|
|
```
|
2011-04-05 17:57:25 +02:00
|
|
|
|
|
|
|
Standard characters allowed in uniuri string.
|
|
|
|
|
|
|
|
|
2011-04-16 21:39:53 +02:00
|
|
|
Functions
|
|
|
|
---------
|
2011-04-05 17:57:25 +02:00
|
|
|
|
2011-04-16 21:39:53 +02:00
|
|
|
### func New
|
2011-04-05 17:57:25 +02:00
|
|
|
|
2013-09-23 18:32:11 +02:00
|
|
|
```go
|
|
|
|
func New() string
|
|
|
|
```
|
|
|
|
|
2011-04-05 19:56:42 +02:00
|
|
|
New returns a new random string of the standard length, consisting of
|
|
|
|
standard characters.
|
2011-04-05 17:57:25 +02:00
|
|
|
|
2011-04-16 21:39:53 +02:00
|
|
|
### func NewLen
|
2011-04-05 17:57:25 +02:00
|
|
|
|
2013-09-23 18:32:11 +02:00
|
|
|
```go
|
|
|
|
func NewLen(length int) string
|
|
|
|
```
|
|
|
|
|
2011-04-05 19:56:42 +02:00
|
|
|
NewLen returns a new random string of the provided length, consisting of
|
|
|
|
standard characters.
|
2011-04-05 17:57:25 +02:00
|
|
|
|
2011-04-16 21:39:53 +02:00
|
|
|
### func NewLenChars
|
2011-04-05 17:57:25 +02:00
|
|
|
|
2013-09-23 18:32:11 +02:00
|
|
|
```go
|
|
|
|
func NewLenChars(length int, chars []byte) string
|
|
|
|
```
|
|
|
|
|
2011-04-05 19:56:42 +02:00
|
|
|
NewLenChars returns a new random string of the provided length, consisting
|
|
|
|
of the provided byte slice of allowed characters (maximum 256).
|
2011-04-16 21:39:53 +02:00
|
|
|
|