core

package
v0.0.0-...-42df0dd Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	WatchReStartInterval time.Duration = 3 * time.Second // 监听重启间隔; 如果panic, 重启间隔
	WatchRetryInterval   time.Duration = 3 * time.Second // 监听重试次数; 如果更新状态失败,重试间隔
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// ModuleID             int32 // 模块id
	ModuleName    string `json:"module_name,omitempty"`
	Desc          string `json:"desc,omitempty"`
	IDKind        int8   `json:"id_kind,omitempty"`        // id类型
	LoadNum       int32  `json:"load_num,omitempty"`       // 每批生成数量
	LoadThreshold int32  `json:"load_threshold,omitempty"` // 加载阀值

	IncrFirstID int64 `json:"incr_first_id,omitempty"` // 第一个id
}

type ConfigLoader

type ConfigLoader interface {
	// 获取所有生成器生成配置
	AllConfigs() ([]*Config, error)
	// 获取生成器生成配置
	Config(name string) (*Config, error)
	// 更新生成器生成配置
	SaveConfig(name string, s *Config) error
}

type IDGenerator

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

Generator.

func NewGenerator

func NewGenerator(name string, sl StatusLoader, opts ...Option) *IDGenerator

func (*IDGenerator) NextID

func (g *IDGenerator) NextID() int64

type Option

type Option func(*Config)

func WithConfig

func WithConfig(cfg *Config) Option

Config 配置

func WithLoadNum

func WithLoadNum(num int32) Option

WithLoadNum 设置每批生成数量

func WithLoadThreshold

func WithLoadThreshold(threshold int32) Option

WithLoadThreshold 设置加载阀值

type Status

type Status struct {
	ModuleID   int32 // 模块id
	ModuleName string
	LastID     int64 // 最后生成的id
}

type StatusLoader

type StatusLoader interface {
	// 获取所有生成器生成状态
	AllStatus() ([]*Status, error)
	// 获取生成器生成状态
	Status(name string) (*Status, error)
	// 更新生成器生成状态
	SaveStatus(name string, s *Status) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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