Documentation
¶
Index ¶
- Constants
- func GetModuleExchange() *socket.ModuleExchange
- func GetModules() map[string]*ModuleInfo
- func GracefulShutdown()
- func Register(m Module, opts ...string)
- func Run()
- func StartModules()
- type Module
- type ModuleInfo
- type ModuleRestartPolicy
- type RestartType
- type SimpleModule
- type SimpleModuleOption
- type SimpleModuleOptions
Constants ¶
View Source
const ( DefaultRestartIntervalLimit = 30 * time.Second DefaultIntervalSecond = 1 )
Variables ¶
This section is empty.
Functions ¶
func GetModuleExchange ¶ added in v1.9.3
func GetModuleExchange() *socket.ModuleExchange
GetModuleExchange return module exchange
func GracefulShutdown ¶
func GracefulShutdown()
GracefulShutdown is if it gets the special signals it does modules cleanup
Types ¶
type Module ¶
type Module interface {
// Name returns the module name.
Name() string
// Group returns the module group.
Group() string
// Enable returns the module enabled.
Enable() bool
// Start starts the module. This is a runtime function, so error handling is left to the user's control.
// Normally, you can print the error in the Start() and interrupt the module process with the 'return' keyword.
// You also can define restart handling by RestartPolicy(), and use panic() to trigger 'OnFailure' restart policy.
Start()
// RestartPolicy returns the module's restart policy.
// If the module does not require a restart policy, return nil.
RestartPolicy() *ModuleRestartPolicy
}
Module interface
type ModuleInfo ¶ added in v1.10.3
type ModuleInfo struct {
// contains filtered or unexported fields
}
ModuleInfo represent a module info
func (*ModuleInfo) GetModule ¶ added in v1.10.3
func (m *ModuleInfo) GetModule() Module
GetModule gets module
type ModuleRestartPolicy ¶ added in v1.22.0
type ModuleRestartPolicy struct {
// RestartType is the type of restart policy
RestartType RestartType
// Retries indicates the number of restarts. If the value is 0, will always restart.
Retries int32
// IntervalSecond is the interval seconds between each restart. Default is 1 second.
IntervalSecond int32
// IntervalTimeGrowthRate is the growth rate of the time interval between restarts.
// The value must be greater than 1, otherwise it will be ignored.
// The interval between each restart is: IntervalTime * IntervalTimeGrowthRate.
IntervalTimeGrowthRate float64
// RestartIntervalLimit is the maximum time interval between restarts. Default is 30 seconds.
RestartIntervalLimit time.Duration
// ErrorHandler if the Retries is set and reaches the maximum, this method is used to customize error handling.
// The default handling is to print the error log.
ErrorHandler func(err error)
}
ModuleRestartPolicy is module restart policy
type RestartType ¶ added in v1.22.0
type RestartType string
RestartType is restart policy type
const ( // RestartPolicyAlways always restart RestartTypeAlways RestartType = "Always" // RestartPolicyOnFailure on failure restart RestartTypeOnFailure RestartType = "OnFailure" )
type SimpleModule ¶ added in v1.22.0
type SimpleModule struct {
// StartFunc indicates the module start function.
StartFunc func()
// StartEFunc indicates the module start function that can return an error.
// The module will panic the error if the function returns an error.
StartEFunc func() error
// contains filtered or unexported fields
}
SimpleModule is the basic structure for rapid development of a module. In most cases, developers only focus on implementing the Start() function, and writing the implementation of other functions is obviously redundant work.
func NewSimpleModule ¶ added in v1.22.0
func NewSimpleModule(name, group string, opts ...SimpleModuleOption) *SimpleModule
func (SimpleModule) Enable ¶ added in v1.22.0
func (m SimpleModule) Enable() bool
func (SimpleModule) Group ¶ added in v1.22.0
func (m SimpleModule) Group() string
func (SimpleModule) Name ¶ added in v1.22.0
func (m SimpleModule) Name() string
func (SimpleModule) RestartPolicy ¶ added in v1.22.0
func (m SimpleModule) RestartPolicy() *ModuleRestartPolicy
func (SimpleModule) Start ¶ added in v1.22.0
func (m SimpleModule) Start()
type SimpleModuleOption ¶ added in v1.22.0
type SimpleModuleOption func(*SimpleModule)
func WithEnable ¶ added in v1.22.0
func WithEnable(enable bool) SimpleModuleOption
func WithRestartPolicy ¶ added in v1.22.0
func WithRestartPolicy(restartPolicy *ModuleRestartPolicy) SimpleModuleOption
type SimpleModuleOptions ¶ added in v1.22.0
type SimpleModuleOptions struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.