Skip to content

Commit

Permalink
docs: updated example and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
HotPotatoC committed Dec 31, 2021
1 parent d40dba4 commit 419f008
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ fmt.Printf("Machine ID: %d\n", parsed.Discriminator) // 1

```go
machineID := uint64(1)
processID := uint64(os.Getpid())
processID := uint64(24)
sf := snowflake.New2(machineID, processID)

id := sf.NextID()
fmt.Println(id)
// 1292058526532767744
// 1292065108376162304

// or

id = snowflake.New2(machineID, processID).NextID()
fmt.Println(id)
// 1292058526532767744
// 1292065108376162304
```

4. Parsing a snowflake id with 2 discriminator fields

```go
parsed := snowflake.Parse2(1292062458947571712)
parsed := snowflake.Parse2(1292065108376162304)

fmt.Printf("Timestamp: %d\n", parsed.Timestamp) // 1640944495572
fmt.Printf("Sequence: %d\n", parsed.Sequence) // 0
Expand Down
4 changes: 2 additions & 2 deletions example/parsing-2-fields/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
)

func main() {
parsed := snowflake.Parse2(1292062458947571712)
parsed := snowflake.Parse2(1292065108376162304)

fmt.Printf("Timestamp: %d\n", parsed.Timestamp) // 1640944495572
fmt.Printf("Timestamp: %d\n", parsed.Timestamp) // 1640945127245
fmt.Printf("Sequence: %d\n", parsed.Sequence) // 0
fmt.Printf("Machine ID: %d\n", parsed.Discriminator1) // 1
fmt.Printf("Process ID: %d\n", parsed.Discriminator2) // 24
Expand Down

0 comments on commit 419f008

Please sign in to comment.