Options are optional values for a Space.
type Options struct { Sep rune // Separates parts of the UID. Defaults to '-'. Time time.Time // Timestamp for all UIDs made with this space. Defaults to current time. // Short, if true, makes the result of space.New shorter by 6 characters. // This can be useful for character restricted IDs. It will use a shorter // but less readable time representation, and will only use two characters // for the count suffix instead of four. // // e.x. normal: gotest-20181030-59751273685000-0001 // e.x. short: gotest-1540917351273685000-01 Short bool }
A Space manages a set of unique IDs distinguished by a prefix.
type Space struct { Prefix string // Prefix of UIDs. Read-only. Sep rune // Separates UID parts. Read-only. Time time.Time // Timestamp for UIDs. Read-only. // contains filtered or unexported fields }
func NewSpace(prefix string, opts *Options) *Space
NewSpace creates a new UID space. A UID Space is used to generate unique IDs.
func (s *Space) New() string
New generates a new unique ID. The ID consists of the Space's prefix, a timestamp, and a counter value. All unique IDs generated in the same test execution will have the same timestamp.
Aside from the characters in the prefix, IDs contain only letters, numbers and sep.
func (s *Space) Older(uid string, d time.Duration) bool
Older reports whether uid was created by m and has a timestamp older than the current time by at least d.
func (s *Space) Timestamp(uid string) (time.Time, bool)
Timestamp extracts the timestamp of uid, which must have been generated by s. The second return value is true on success, false if there was a problem.