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 any) 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 Node
- type ParseError
Constants ¶
const ( ErrNoHardwareAddress = merr.Code("no_hardware_address") ErrNotDockerized = merr.Code("not_dockerized") )
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(ctx context.Context) (InstanceID, error)
NewDockerID returns a DockerID for the current Docker container.
func NewHardwareID ¶
func NewHardwareID(ctx context.Context) (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 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