Skip to content

Commit 6acf88a

Browse files
committed
Update README
1 parent ae2fafc commit 6acf88a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,30 @@ u, err := uuid.FromBytes([]byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1,
4040
var u uuid.UUID
4141
err := db.QueryRow("SELECT id FROM users WHERE email = $1", email).Scan(&u)
4242
if u.IsNil() {
43-
// Handle nil row
43+
// Handle nil UUID
4444
}
4545
```
4646

47+
## Setting a default format
48+
49+
Changing the default format will affect how UUIDs are marshaled to strings from `MarshalText`, and `MarshalJSON`.
50+
51+
52+
```go
53+
import (
54+
"encoding/json"
55+
"github.com/flexstack/uuid"
56+
)
57+
58+
uuid.DefaultFormat = uuid.FormatBase58
59+
60+
u := uuid.FromStringOrNil("ffffffff-ffff-ffff-ffff-ffffffffffff")
61+
62+
// Marshal to base58
63+
m := map[string]uuid.UUID{"id": u}
64+
b, err := json.Marshal(m)
65+
fmt.Println(string(b)) // {"id": "YcVfxkQb6JRzqk5kF2tNLv"}
66+
```
4767

4868
## Credit
4969

0 commit comments

Comments
 (0)