Documentation ¶
Index ¶
- Constants
- func Rand(w byte) int64
- func SeqID(host, node int64) (func(args ...int64) int64, error)
- func Simple(server int64) (func() int64, error)
- type Base64
- type Bits
- func Arg(width byte, index int, fallback int64) Bits
- func Data(width byte, key string, index int, fallback int64) Bits
- func Env(width byte, name string, fallback int64) Bits
- func Fixed(width byte, value int64) Bits
- func Host(width byte, fallback int64) Bits
- func Node(width byte, fallback int64) Bits
- func Option(width byte, key string, fallback int64) Bits
- func Random(width byte) Bits
- func Sequence(width byte) Bits
- func Timestamp(width byte, t DateTimeType) Bits
- type Builder
- type DataProvider
- type DataSource
- type DataWrapper
- type DateTimeType
- type DebugInfo
- type DecodeError
- type Encoder
- type ID
- type Options
- type OptionsError
Constants ¶
const ( // Min indicates the minimum days approaching the end that the system limits Min int64 = 7 * msPerDay // EpochMS is the default start timestamp, // measured in milliseconds starting // at midnight on December 12, 2022 EpochMS = 1_670_774_400_000 )
const ( // HostWidth is the default width of the bits segment, // value range [0, 63] HostWidth = 6 // NodeWidth is the default width of the bits segment, // value range [0, 15] NodeWidth = 4 // TimestampWidth is the default width of the bits segment. // It measures time by the number of seconds that have // elapsed since EpochMS, value range [0, 68 years after] TimestampWidth = 41 // SequenceWidth is the default width of the bits segment, // value range [0, 4095] SequenceWidth = 12 )
Variables ¶
This section is empty.
Functions ¶
func Rand ¶
rand generates a secure random number with a width specified by w, which is the expected bit width, value range is [1, 63].
func SeqID ¶
SeqID implements sequential identifiers. The value range of host is [0, 63]. The value range of node is [0, 15].
if c, e := SeqID(10, 10); e == nil { fmt.Println("ID: ", c()) }
Types ¶
type Bits ¶
type Bits struct { // Source indicates that bits segment data source Source DataSource Width byte Value int64 // Key indicates the data source key Key string // Index indicates the data source index Index int // contains filtered or unexported fields }
func Timestamp ¶
func Timestamp(width byte, t DateTimeType) Bits
Timestamp to make a bits segment, which value from system unix timestamp
type Builder ¶
type Builder struct { sync.Mutex Encoder Encoder Debug bool // contains filtered or unexported fields }
func Snowflake ¶
Snowflake implements the common snowflake algorithm. The value range of host is [0, 63]. The value range of node is [0, 15].
func (*Builder) NextString ¶
func (*Builder) ResetEpoch ¶
type DataProvider ¶
type DataSource ¶
type DataSource int
const ( // Static indicates that the value is from default Static DataSource = iota // Args indicates that the value is from arguments of caller Args // OS indicates that the value is from OS environment OS // Settings indicates that the value is from options Settings // SequenceID indicates that the value is from sequence value SequenceID // DateTime indicates that the value is from system unix timestamp in nanoseconds DateTime // Random indicates that the value is from a random number RandomID // Provider indicates that the value is from data provider Provider )
func (DataSource) String ¶
func (d DataSource) String() string
type DataWrapper ¶
type DataWrapper struct {
// contains filtered or unexported fields
}
func (*DataWrapper) Write ¶
func (w *DataWrapper) Write(name string, data ...int64) *DataWrapper
type DateTimeType ¶
type DateTimeType int
const ( TimestampMilliseconds DateTimeType = iota TimestampNanoseconds TimestampMicroseconds TimestampSeconds TimeMillisecond TimeSecond TimeMinute TimeHour TimeDay TimeMonth TimeYear TimeYearDay TimeWeekday TimeWeekNumber )
func (DateTimeType) String ¶
func (d DateTimeType) String() string
type DecodeError ¶
func (*DecodeError) Error ¶
func (e *DecodeError) Error() string
func (*DecodeError) Unwrap ¶
func (e *DecodeError) Unwrap() error
type Options ¶
type Options struct { // Min indicates the minimum days approaching the end Min, EpochMS int64 // Signed is used to on/off the sign bit Signed bool // contains filtered or unexported fields }
Options MUST include DateTime segment AND SequenceID segment
func Config ¶
Config is a shortcut for make Options, segments MUST include DateTime segment AND SequenceID segment.
func Default ¶
Default is a shortcut for make Options, segments MUST include DateTime segment AND SequenceID segment.
func Define ¶
Define is a shortcut for make Options, segments MUST include DateTime segment AND SequenceID segment.
func (*Options) Bind ¶
func (o *Options) Bind(p DataProvider) *Options
Bind to bind the data provider
type OptionsError ¶
func (*OptionsError) Error ¶
func (e *OptionsError) Error() string
func (*OptionsError) SameAs ¶
func (e *OptionsError) SameAs(err error) bool
func (*OptionsError) Unwrap ¶
func (e *OptionsError) Unwrap() error