unique_id

package
v0.0.0-...-83425ee Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUniqueId

func GetUniqueId(business string) (uint64, error)

func UpdateIdSet

func UpdateIdSet(list BufferInterface)

func UpdateWareHouse

func UpdateWareHouse(business_type string)

Types

type Buffer

type Buffer struct {
	Start   uint64 // the start value of id
	Current uint64 // current id value, plus one per time when id was acquired
	End     uint64 // the max value of id

	Duration uint64 // End - Start
	Cap      uint64 // End - Current

	Num         int  // the serial number
	Fulling     bool // if getting the buffer full
	Initialized bool

	BufferSource BufferInterface
	// contains filtered or unexported fields
}

func NewBuffer

func NewBuffer(index int, s interface{}) *Buffer

func (*Buffer) GetBufferFull

func (b *Buffer) GetBufferFull()

func (*Buffer) ReleaseId

func (b *Buffer) ReleaseId() (id uint64, empty bool)

func (*Buffer) SetSource

func (b *Buffer) SetSource(s interface{})

type BufferInterface

type BufferInterface interface {
	Duration() uint64
	StartAt() uint64
	EndAT() uint64
	Update() error
	Usable() bool
	BusinessId() string
}

type IdSet

type IdSet struct {
	Set []*Buffer

	Count       int // len(Set)
	SetIndexMax int // Count - 1

	Index int
	// contains filtered or unexported fields
}

func GetNewIdSet

func GetNewIdSet(count int, source interface{}) *IdSet

func (*IdSet) Current

func (i *IdSet) Current() *Buffer

func (*IdSet) GetId

func (i *IdSet) GetId() uint64

func (*IdSet) Reload

func (i *IdSet) Reload(count int, source interface{})

type UniqueIdRpcService

type UniqueIdRpcService struct{}

func (*UniqueIdRpcService) MakeUniqueId

func (u *UniqueIdRpcService) MakeUniqueId(c ctx.Context, business *id_rpc.BusinessType) (*id_rpc.UniqueId, error)

type WareHouse

type WareHouse struct {
	HouseMap map[string]*IdSet // every business type has an IdSet
	// contains filtered or unexported fields
}
var House *WareHouse

generate ID uniquely and increasingly the ID is an integer that created from database

func NewWareHouse

func NewWareHouse() *WareHouse

func (*WareHouse) Acquire

func (w *WareHouse) Acquire(business string) (uint64, error)

func (*WareHouse) AddNewToWareHouse

func (w *WareHouse) AddNewToWareHouse(business_type string, set *IdSet)

func (*WareHouse) Get

func (w *WareHouse) Get(business_type string) (*IdSet, bool)

func (*WareHouse) RemoveToWareHouse

func (w *WareHouse) RemoveToWareHouse(business_type string)

func (*WareHouse) SetHouse

func (w *WareHouse) SetHouse(business string, set *IdSet)

Jump to

Keyboard shortcuts

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