Bootstrap

Mainly used to add some logic after the framework initialization to bootstrap the business system startup and to perform some cleanup logic after the system stops, for example the gorm database connection in the framework is connected and disconnected through bootstrap

Detailed examples referenceherearrow-up-right

How to implement

Implement the following methods

// Initiator methods that need to be implemented
type Initiator interface {
	// Start
	Start() error
	// Stop
	Stop()
}

Bootstrap

Executed after framework initialization and before service start

Add to bootstrap queue

import "github.com/asjard/asjard/core/bootstrap"

type CustomeBootstrap struct{}

// The following method will be executed after system initialization
func(CustomeBootstrap) Start() error {return nil}
// The following method will be executed after system stop
func(CustomeBootstrap) Stop() {}

func init() {
	// Add to startup bootstrap queue
	bootstrap.AddBootstrap(&CustomeBootstrap{})
}

Example

You can refer tohttps://github.com/asjard/asjard/blob/main/pkg/stores/xgorm/xgorm.goarrow-up-right

Initiator

Executed after local configuration files are loaded

Add to initialization queue

You can refer toetcd connectionarrow-up-rightImplement

Last updated