package ksuid

Import Path
	github.com/segmentio/ksuid (on go.dev)

Dependency Relation
	imports 11 packages, and imported by one package


Package-Level Type Names (total 4)
/* sort by: | */
CompressedSet is an immutable data type which stores a set of KSUIDs. String satisfies the fmt.GoStringer interface, returns a Go representation of the set. Iter returns an iterator that produces all KSUIDs in the set. String satisfies the fmt.Stringer interface, returns a human-readable string representation of the set. CompressedSet : github.com/ChrisTrenkamp/goxpath/tree.Result CompressedSet : fmt.GoStringer CompressedSet : fmt.Stringer func AppendCompressed(set []byte, ids ...KSUID) CompressedSet func Compress(ids ...KSUID) CompressedSet
CompressedSetIter is an iterator type returned by Set.Iter to produce the list of KSUIDs stored in a set. Here's is how the iterator type is commonly used: for it := set.Iter(); it.Next(); { id := it.KSUID // ... } CompressedSetIter values are not safe to use concurrently from multiple goroutines. KSUID is modified by calls to the Next method to hold the KSUID loaded by the iterator. Next moves the iterator forward, returning true if there a KSUID was found, or false if the iterator as reached the end of the set it was created from. func CompressedSet.Iter() CompressedSetIter
KSUIDs are 20 bytes: 00-03 byte: uint32 BE UTC timestamp with custom epoch 04-19 byte: random "payload" Append appends the string representation of i to b, returning a slice to a potentially larger memory area. Raw byte representation of KSUID Get satisfies the flag.Getter interface, making it possible to use KSUIDs as part of of the command line options of a program. IsNil returns true if this is a "nil" KSUID ( KSUID) MarshalBinary() ([]byte, error) ( KSUID) MarshalText() ([]byte, error) Next returns the next KSUID after id. The 16-byte random payload without the timestamp Prev returns the previoud KSUID before id. Scan implements the sql.Scanner interface. It supports converting from string, []byte, or nil into a KSUID value. Attempting to convert from another type will return an error. Set satisfies the flag.Value interface, making it possible to use KSUIDs as part of of the command line options of a program. String-encoded representation that can be passed through Parse() The timestamp portion of the ID as a Time object The timestamp portion of the ID as a bare integer which is uncorrected for KSUID's special epoch. (*KSUID) UnmarshalBinary(b []byte) error (*KSUID) UnmarshalText(b []byte) error Value converts the KSUID into a SQL driver value which can be used to directly use the KSUID as parameter to a SQL query. KSUID : github.com/ChrisTrenkamp/goxpath/tree.Result *KSUID : database/sql.Scanner KSUID : database/sql/driver.Valuer KSUID : encoding.BinaryMarshaler *KSUID : encoding.BinaryUnmarshaler KSUID : encoding.TextMarshaler *KSUID : encoding.TextUnmarshaler *KSUID : flag.Getter *KSUID : flag.Value KSUID : fmt.Stringer func FromBytes(b []byte) (KSUID, error) func FromParts(t time.Time, payload []byte) (KSUID, error) func New() KSUID func NewRandom() (ksuid KSUID, err error) func NewRandomWithTime(t time.Time) (ksuid KSUID, err error) func Parse(s string) (KSUID, error) func KSUID.Next() KSUID func KSUID.Prev() KSUID func (*Sequence).Bounds() (min KSUID, max KSUID) func (*Sequence).Bounds() (min KSUID, max KSUID) func (*Sequence).Next() (KSUID, error) func AppendCompressed(set []byte, ids ...KSUID) CompressedSet func Compare(a, b KSUID) int func Compress(ids ...KSUID) CompressedSet func IsSorted(ids []KSUID) bool func Sort(ids []KSUID) var Max var Nil
Sequence is a KSUID generator which produces a sequence of ordered KSUIDs from a seed. Up to 65536 KSUIDs can be generated by for a single seed. A typical usage of a Sequence looks like this: seq := ksuid.Sequence{ Seed: ksuid.New(), } id, err := seq.Next() Sequence values are not safe to use concurrently from multiple goroutines. The seed is used as base for the KSUID generator, all generated KSUIDs share the same leading 18 bytes of the seed. Bounds returns the inclusive min and max bounds of the KSUIDs that may be generated by the sequence. If all ids have been generated already then the returned min value is equal to the max. Next produces the next KSUID in the sequence, or returns an error if the sequence has been exhausted.
Package-Level Functions (total 12)
AppendCompressed uses the given byte slice as pre-allocated storage space to build a KSUID set. Note that the set uses a compression technique to store the KSUIDs, so the resuling length is not 20 x len(ids). The rule of thumb here is for the given byte slice to reserve the amount of memory that the application would be OK to waste.
Implements comparison for KSUID type
Compress creates and returns a compressed set of KSUIDs from the list given as arguments.
Constructs a KSUID from a 20-byte binary representation
Constructs a KSUID from constituent parts
IsSorted checks whether a slice of KSUIDs is sorted
Generates a new KSUID. In the strange case that random bytes can't be read, it will panic.
Generates a new KSUID
func NewRandomWithTime(t time.Time) (ksuid KSUID, err error)
Parse decodes a string-encoded representation of a KSUID object
Sets the global source of random bytes for KSUID generation. This should probably only be set once globally. While this is technically thread-safe as in it won't cause corruption, there's no guarantee on ordering.
Sorts the given slice of KSUIDs
Package-Level Variables (total 3)
FastRander is an io.Reader that uses math/rand and is optimized for generating 16 bytes KSUID payloads. It is intended to be used as a performance improvements for programs that have no need for cryptographically secure KSUIDs and are generating a lot of them.
Represents the highest value a KSUID can have
Represents a completely empty (invalid) KSUID