Documentation
¶
Overview ¶
Package autoinc 用于产生自增 ID
ai := autoinc.New(0, 1, 1)
ctx, cancel = context.WithCancel(context.Background())
defer cancel()
go ai.Serve(ctx)
for i:=0; i<10; i++ {
fmt.Println(ai.ID())
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AutoInc ¶
type AutoInc struct {
// contains filtered or unexported fields
}
func New ¶
New 声明一个新的 AutoInc 实例
start:起始数值; step:步长,可以为负数,但不能为 0; bufferSize:缓存的长度。
如果 step 为 0,会直接 panic
func (*AutoInc) Serve ¶
Serve 运行该服务
这是个阻塞方法,只有此方法运行之后,AutoInc.ID 等才有返回值。
当前自增项超过最大值时,会返回 ErrOverflow 错误。
Click to show internal directories.
Click to hide internal directories.