Documentation ¶
Overview ¶
Package idgen
(集中 server 部署情况下, 不需要区分 scope) normal: 32b timestamp(second) + 10b timestamp(millisecond) + 8b counter + 14b server_id (1 + 13b id_server_id) custom: 32b timestamp(second) + 18b custom_counter + 01 + 12b scope_id fallback: 32b timestamp(second) + 10b timestamp(millisecond) + 8b counter + 00 + 12b scope_id fake: 32b timestamp(second) + 10b timestamp(millisecond) + 8b counter + 00 + 000000000000
todo: 支持 counter 向 timestamp 借位
Index ¶
Constants ¶
const ( ControlIDDigits = 14 CounterDigits = 8 ControlDigitsPos = 1 << 13 )
Variables ¶
var ErrGenerateIDFailed = errors.New("generate id failed")
Functions ¶
This section is empty.
Types ¶
type IDGen ¶
type IDGen struct {
// contains filtered or unexported fields
}
func NewIDGen ¶
func NewIDGen(generators ...IGenerator) *IDGen
type IGenerator ¶
type IGenerator interface { Get(ctx context.Context) (int64, error) MGet(ctx context.Context, count int64) ([]int64, error) }
func NewFakeGen ¶
func NewFakeGen() IGenerator
NewFakeGen returns a fake generator rule: 32b timestamp(second) + 10b timestamp(millisecond) + 8b counter + 00 + 000000000000
type LocalMUGen ¶
type LocalMUGen struct { syncounter.Counter // contains filtered or unexported fields }
func NewLocalMUGen ¶
func NewLocalMUGen(scopeID int64, fallback bool) *LocalMUGen
NewLocalMUGen fallback: 32b timestamp(second) + 10b timestamp(millisecond) + 8b counter + 00 + 12b scope_id 分为运行在 global server 和运行在业务 server 两种模式, 后者为 fallback todo: 允许 counter 向 timestamp 借位