Documentation
¶
Overview ¶
Package sfid generates snowflake-style int64 IDs from a clock, a worker id and a per-tick sequence.
NewDefaultIDGen uses 1ms clock units, epoch 2025-05-21T00:00:00Z, 10 worker bits and 12 sequence bits. NewIDGen customizes all of them; the layout must allow at least 10 years of IDs from the epoch. A generator returns an error from ID when the clock moves backwards within 5ms; MustID panics instead.
Attach a generator with With / Carry and fetch it with From / Must. WorkerIDFromLocalIP derives a worker id from the last two octets of the first non-loopback IPv4 address.
Usage:
ctx := sfid.With(context.Background(), sfid.NewDefaultIDGen(1)) id := sfid.Must(ctx).MustID()
This package replaces the archived module github.com/xoctopus/sfid.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( NewFactory = factory.NewFactory NewWorker = factory.NewWorker )