autoinc

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2019 License: MIT Imports: 2 Imported by: 4

README

autoinc Build Status license codecov

autoinc 提供了一个简单的 ID 自增功能。

ai := autoinc.New(0, 1, 1)
for i:=0; i<10; i++ {
    fmt.Println(ai.MustID())
}
安装
go get github.com/issue9/autoinc
文档

Go Walker GoDoc

版权

本项目采用 MIT 开源授权许可证,完整的授权说明可在 LICENSE 文件中找到。

Documentation

Overview

Package autoinc 用于产生唯一 ID,可以指定起始 ID 和步长。

ai := autoinc.New(0, 1, 1)
for i:=0; i<10; i++ {
    fmt.Println(ai.ID())
}

ai.Stop()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoInc

type AutoInc struct {
	// contains filtered or unexported fields
}

AutoInc 用于产生唯一 ID。

func New

func New(start, step int64, bufferSize int) *AutoInc

New 声明一个新的 AutoInc 实例。

start:起始数值; step:步长,可以为负数,但不能为 0; bufferSize:缓存的长度。

如果 step 为 0,会直接 panic

func (*AutoInc) ID

func (ai *AutoInc) ID() (int64, bool)

ID 获取 ID 值。

第二个参数若返回 false,表示当前的 ID 值已经失效。

func (*AutoInc) MustID

func (ai *AutoInc) MustID() int64

MustID 获取 ID 值,若不成功,则 panic。

func (*AutoInc) Stop

func (ai *AutoInc) Stop()

Stop 停止计时

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL