uid

package
v0.31.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package uid supports generating unique IDs. Its chief purpose is to prevent multiple test executions from interfering with each other, and to facilitate cleanup of old entities that may remain if tests exit early.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

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.
}

Options are optional values for a Space.

type Space

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
}

A Space manages a set of unique IDs distinguished by a prefix.

func NewSpace

func NewSpace(prefix string, opts *Options) *Space

NewSpace creates a new UID space. A UID Space is used to generate unique IDs.

func (*Space) New

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 (*Space) Older

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 (*Space) Timestamp

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL