Skip to content

go-extreme/bootstrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bootstrapper

A lightweight Go package for managing application initialization order with dependency injection support.

Features

  • Register components with custom initialization order
  • Thread-safe shared state management
  • Automatic lifecycle management (Booting/Booted phases)
  • Predefined order constants for common components

Usage

Basic Registration

package main

type Database struct{}

func (d *Database) Booting() {
    // Initialize database connection
}

func (d *Database) Booted() {
    // Run migrations or post-init tasks
}

func main() {
    db := &Database{}
    bootstrapper.Register(db, bootstrapper.OrderDB)
    
    bootstrapper.StartBooting()
    bootstrapper.StartBooted()
}

Custom Order

const CustomOrder = 50

service := &MyService{}
bootstrapper.Register(service, CustomOrder)

Shared State

// Store shared data
bootstrapper.Share("config", myConfig)

// Retrieve shared data
config := bootstrapper.Get("config")

Predefined Orders

  • OrderConfig (1) - Configuration
  • OrderDB (2) - Database
  • OrderCache (3) - Cache
  • OrderQueue (4) - Queue
  • WorkerPool (5) - Worker Pool
  • OrderRepository (6) - Repository
  • OrderService (7) - Service
  • OrderController (8) - Controller

Testing

go test -v

License

MIT

About

This package provides a lightweight and deterministic bootstrapping mechanism for Go applications. It allows components to be registered, ordered, and initialized in sequence using convention-based lifecycle hooks (Booting and Booted). The goal is to keep application startup logic simple, explicit, and decoupled

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages