Documentation ¶
Index ¶
- type AllocatedIDStore
- type IDGenerateClient
- func (c *IDGenerateClient) Allocate(id int) error
- func (c *IDGenerateClient) Close() error
- func (c *IDGenerateClient) Connect(addr *net.TCPAddr) error
- func (c *IDGenerateClient) Free(id int) error
- func (c *IDGenerateClient) FreeAll() error
- func (c *IDGenerateClient) Generate() (int, error)
- func (c *IDGenerateClient) GetAllocatedIDCount(id int) (int, error)
- func (c *IDGenerateClient) IsAllocated(id int) (bool, error)
- func (c *IDGenerateClient) Ping() error
- func (c *IDGenerateClient) Reconnect() error
- type IDGenerateServer
- type IDGenerator
- type LocalStore
- type RedisStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AllocatedIDStore ¶
type AllocatedIDStore interface {
// contains filtered or unexported methods
}
AllocatedIDStore stores allocated id.
type IDGenerateClient ¶
type IDGenerateClient struct {
// contains filtered or unexported fields
}
IDGenerateClient requests new id to server.
func (*IDGenerateClient) Allocate ¶
func (c *IDGenerateClient) Allocate(id int) error
Allocate a specified id.
func (*IDGenerateClient) Connect ¶
func (c *IDGenerateClient) Connect(addr *net.TCPAddr) error
Connect to server.
func (*IDGenerateClient) FreeAll ¶
func (c *IDGenerateClient) FreeAll() error
FreeAll free all allocated id.
func (*IDGenerateClient) Generate ¶
func (c *IDGenerateClient) Generate() (int, error)
Generate a new id.
func (*IDGenerateClient) GetAllocatedIDCount ¶
func (c *IDGenerateClient) GetAllocatedIDCount(id int) (int, error)
GetAllocatedIDCount is getter for allocatedIDCount.
func (*IDGenerateClient) IsAllocated ¶
func (c *IDGenerateClient) IsAllocated(id int) (bool, error)
IsAllocated check if specified id is allocated.
func (*IDGenerateClient) Ping ¶
func (c *IDGenerateClient) Ping() error
Ping verifies a connection to the server is still alive.
func (*IDGenerateClient) Reconnect ¶
func (c *IDGenerateClient) Reconnect() error
Reconnect connects to the server if a connection to the server is not alive.
type IDGenerateServer ¶
type IDGenerateServer struct {
// contains filtered or unexported fields
}
IDGenerateServer generate id when requested by client.
func NewServer ¶
func NewServer(store AllocatedIDStore, tcpAddr *net.TCPAddr) (*IDGenerateServer, error)
NewServer is IDGenerateServer constructed.
func (*IDGenerateServer) Pause ¶
func (s *IDGenerateServer) Pause() error
Pause server while maintaining allocated id.
func (*IDGenerateServer) SetLogger ¶
func (s *IDGenerateServer) SetLogger(logger *log.Logger)
SetLogger is setter for logger.
func (*IDGenerateServer) Stop ¶
func (s *IDGenerateServer) Stop() error
Stop server and free all allocated id.
type IDGenerator ¶
type IDGenerator struct {
// contains filtered or unexported fields
}
IDGenerator generate a id.
func NewIDGenerator ¶
func NewIDGenerator(store AllocatedIDStore) (*IDGenerator, error)
NewIDGenerator is IDGenerator constructed.
func (*IDGenerator) Allocate ¶
func (g *IDGenerator) Allocate(id int) error
Allocate a specified id.
func (*IDGenerator) GetAllocatedIDCount ¶
func (g *IDGenerator) GetAllocatedIDCount() (int, error)
GetAllocatedIDCount is getter for allocatedIDCount.
func (*IDGenerator) IsAllocated ¶
func (g *IDGenerator) IsAllocated(id int) (bool, error)
IsAllocated check if specified id is allocated.
type LocalStore ¶
type LocalStore struct {
// contains filtered or unexported fields
}
LocalStore stores allocated id to byte slice.
func NewLocalStore ¶
func NewLocalStore(maxSize int) (*LocalStore, error)
NewLocalStore is LocalStore constructed.
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore stores allocated id to redis.
func NewRedisStore ¶
func NewRedisStore(host, key string, maxSize int) (*RedisStore, error)
NewRedisStore is RedisStore constructed.