modules

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 11 Imported by: 21

README

Getting Started with modules

What's the use?

Use instead of func init() { } to accomplish what you expect by an explicit initialization sequence

What modules are available for farseer-go?

  • cache.Module
  • cacheMemory.Module
  • data.Module
  • elasticSearch.Module
  • eventBus.Module
  • fSchedule.Module
  • queue.Module
  • rabbit.Module
  • redis.Module
  • tasks.Module

Add your StartupModule Files

type StartupModule struct {
}

// Dependent modules
func (module StartupModule) DependsModule() []modules.FarseerModule {
    return []modules.FarseerModule{interfaces.Module{}, infrastructure.Module{}}
}

// Pre-initialization
func (module StartupModule) PreInitialize() {
}

// Initialize
func (module StartupModule) Initialize() {
}

// PostInitialize
func (module StartupModule) PostInitialize() {
}

// Shutdown
func (module StartupModule) Shutdown() {
}

DependsModule

DependsModule is used to load modules that you need to depend on, such as data.Module, redis.Module, cache.Module, or your business module

Initialization

// First all dependent modules will be loaded according to DependsModule's dependencies.
// and perform the initialization of each module in the order of dependency
fs.Initialize[StartupModule]("FOPS")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLoad

func IsLoad(module FarseerModule) bool

IsLoad 模块是否加载

func ShutdownModules

func ShutdownModules(farseerModules []FarseerModule)

ShutdownModules 关闭模块

func StartModules

func StartModules(farseerModules []FarseerModule)

StartModules 启动模块

func ThrowIfNotLoad

func ThrowIfNotLoad(module FarseerModule)

ThrowIfNotLoad 如果没加载模块时,退出应用

Types

type FarseerInitializeModule added in v0.8.0

type FarseerInitializeModule interface {
	FarseerModule
	// Initialize 初始化
	Initialize()
}

FarseerInitializeModule 初始化(常用于根据配置设置初始化对象)

type FarseerKernelModule

type FarseerKernelModule struct {
}

func (FarseerKernelModule) DependsModule

func (module FarseerKernelModule) DependsModule() []FarseerModule

func (FarseerKernelModule) PreInitialize

func (module FarseerKernelModule) PreInitialize()

type FarseerModule

type FarseerModule interface {
	// DependsModule 依赖的模块
	DependsModule() []FarseerModule
}

FarseerModule 依赖的模块

func Distinct

func Distinct(modules []FarseerModule) []FarseerModule

Distinct 模块去重

func GetDependModule

func GetDependModule(module ...FarseerModule) []FarseerModule

GetDependModule 查找模块的依赖

func GetDependModules added in v0.8.0

func GetDependModules(startupModule FarseerModule) []FarseerModule

type FarseerPostInitializeModule added in v0.8.0

type FarseerPostInitializeModule interface {
	FarseerModule
	// PostInitialize 初始化之后
	PostInitialize()
}

FarseerPostInitializeModule 初始化之后(常用于启动协程服务)

type FarseerPreInitializeModule added in v0.8.0

type FarseerPreInitializeModule interface {
	FarseerModule
	// PreInitialize 预初始化
	PreInitialize()
}

FarseerPreInitializeModule 预初始化(常用于全局变量初始化)

type FarseerShutdownModule added in v0.8.0

type FarseerShutdownModule interface {
	FarseerModule
	// Shutdown 应用关闭之前先关闭模块
	Shutdown()
}

FarseerShutdownModule 应用关闭之前先关闭模块

Jump to

Keyboard shortcuts

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