Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResetYitterGenerator ¶
func ResetYitterGenerator()
ResetYitterGenerator resets the singleton configuration. ONLY for testing purposes.
Types ¶
type IDGenerator ¶
type IDGenerator interface {
NextID() int64
}
func NewYitterGenerator ¶
func NewYitterGenerator(workerID uint16, opts ...Option) (IDGenerator, error)
NewYitterGenerator creates a new IDGenerator using the yitter snowflake implementation. It requires a workerID, which must be unique for each running instance of the generator. Additional configurations can be provided via functional options. Note: Since the underlying library uses a global singleton, only the FIRST call to NewYitterGenerator will actually configure the generator. Subsequent calls will return the existing generator if the workerID matches, or an error if it doesn't.
type Option ¶
type Option func(*idgen.IdGeneratorOptions)
Option is a function that configures the yitter ID generator.
func WithBaseTime ¶
WithBaseTime sets the base time for the snowflake algorithm in milliseconds. This is useful for compatibility with older systems. Default is 1582206000000 (2020-02-20 22:00:00 UTC).
func WithSeqBitLength ¶
WithSeqBitLength sets the number of bits to use for the sequence number. This limits the number of IDs that can be generated per millisecond. The sum of workerIdBitLength and seqBitLength cannot exceed 22. Default is 6.
func WithWorkerIdBitLength ¶
WithWorkerIdBitLength sets the number of bits to use for the worker ID. The sum of workerIdBitLength and seqBitLength cannot exceed 22. Default is 6.
type TraceGenerator ¶
type TraceGenerator interface {
// NextTraceID Returns a 16-byte globally unique TraceID compliant with W3C standards.
NextTraceID() trace.TraceID
// NextSpanID Returns the 8-byte SpanID in W3C standard format.
NextSpanID() trace.SpanID
ComposeTraceParent(traceId trace.TraceID, spanId trace.SpanID) string
ParseTraceParent(t string) (trace.TraceID, trace.SpanID, error)
}
func NewOtelTraceGenerator ¶
func NewOtelTraceGenerator() TraceGenerator
NewOtelTraceGenerator creates a W3C-compliant ID generator. It does not rely on a global TracerProvider instance, nor does it generate "orphaned" Spans that pollute the backend.