Generate unique IDs which contain a high-resolution timestamp.
Package to generate unique, 64bit integers based on the current nanosecond time. Safe for concurrent use by multiple goroutines. A monotonically increasing int64 is always returned.
This package is designed for self-contained applications that need to generate unique identifiers without relying on an external ID source such as Snowflake (or a database like MySQL).
-
The integers generated have nanosecond resolution. Because the ID contains this time information, it could present an attack vector. If using these as public identifiers, know that the clients will know the exact time the ID was generated.
-
This may generate duplicate numbers if used by multiple application instances (such as a cluster) as the locks only work for a single application's threads.
Most people should use: https://github.com/segmentio/ksuid
Go's time
package has a monotonic clock since Go 1.9. You can read the original Proposal here and the time package documentation on the subject.