blob: b27ef08c0d351104f5e7ea1d3e948fe89ddf6b37 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# snowflake
Generate random, URL-safe identifiers in Go.
Each ID is 16 bytes of cryptographically secure randomness, encoded as a base62 string.
## install
```bash
go get git.ethanwerner.com/snowflake
```
## usage
```go
package main
import (
"fmt"
"git.ethanwerner.com/snowflake"
)
func main() {
id, _ := snowflake.New()
fmt.Println(id) // e.g. "7Kx9mQ2pL4nR8wYv"
fmt.Println(id.Hex()) // e.g. "a1b2c3..."
parsed, _ := snowflake.FromString(id.String())
}
```
## features
- Cryptographically secure random IDs
- Base62 and hex encoding/decoding
- `encoding.TextMarshaler` / `json.Marshaler` support
- `database/sql.Scanner` / `driver.Valuer` support
## license
MIT
|