Documentation ¶
Index ¶
- Constants
- func SetInstanceID(instanceID InstanceID)
- type ID
- func (id ID) Bytes() []byte
- func (id ID) Equal(x ID) bool
- func (id ID) IsZero() bool
- func (id ID) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (id ID) MarshalJSON() ([]byte, error)
- func (id *ID) Scan(src interface{}) error
- func (id ID) String() string
- func (id *ID) UnmarshalBSONValue(t bsontype.Type, raw []byte) (err error)
- func (id *ID) UnmarshalJSON(b []byte) (err error)
- func (id ID) Value() (driver.Value, error)
- type InstanceID
- type Iterator
- type Node
- type ParseError
- type Set
Constants ¶
const Production = "prod"
Production is the internal name for production ksuid, but is omitted during marshaling.
Variables ¶
This section is empty.
Functions ¶
func SetInstanceID ¶
func SetInstanceID(instanceID InstanceID)
SetInstanceID overrides the default instance id in the exported node. This will effect all invocations of the Generate function.
Types ¶
type ID ¶
type ID struct { Environment string Resource string Timestamp uint64 InstanceID InstanceID SequenceID uint32 }
ID is an optionally prefixed, k-sortable globally unique ID.
func (ID) MarshalBSONValue ¶
MarshalBSONValue implements bson.ValueMarshaler
func (ID) MarshalJSON ¶
MarshalJSON implements a custom JSON string marshaler.
func (*ID) Scan ¶
Scan implements a custom database/sql.Scanner to support unmarshaling from standard database drivers.
func (*ID) UnmarshalBSONValue ¶
UnmarshalBSONValue implements bson.ValueUnmarshaler
func (*ID) UnmarshalJSON ¶
UnmarshalJSON implements a custom JSON string unmarshaler.
type InstanceID ¶
func NewDockerID ¶
func NewDockerID() (InstanceID, error)
NewDockerID returns a DockerID for the current Docker container.
func NewHardwareID ¶
func NewHardwareID() (InstanceID, error)
NewHardwareID returns a HardwareID for the current node.
func NewRandomID ¶
func NewRandomID() InstanceID
NewRandomID returns a RandomID initialized by a PRNG.
func (InstanceID) Bytes ¶
func (i InstanceID) Bytes() [8]byte
func (InstanceID) Scheme ¶
func (i InstanceID) Scheme() byte
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator goes over every item currently in the set in a thread-safe way.
type Node ¶
type Node struct { InstanceID InstanceID // contains filtered or unexported fields }
Node contains metadata used for ksuid generation for a specific machine.
func NewNode ¶
func NewNode(environment string, instanceID InstanceID) *Node
NewNode returns a ID generator for the current machine.
type ParseError ¶
type ParseError struct {
// contains filtered or unexported fields
}
ParseError is returned when unexpected input is encountered when parsing user input to an ID.
func (ParseError) Error ¶
func (pe ParseError) Error() string
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a thread-safe, ordered array of KSUID where each item exists exactly once.
All Read/Write operations are O(1). Deletion is O(n).
func NewSet ¶
NewSet initializes a KSUID set for unique sets of KSUID, optionally based on an initial array of KSUID.
func (*Set) Append ¶
Append inserts the given ID to the end of the set, if it does not already exist. Returns true if item is new to the set.
Complexity: O(1)