Skip to content

Simple application lifecycle via callbacks for Go

License

Notifications You must be signed in to change notification settings

eshork/lyfecycle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lyfecycle - Simple application lifecycle via callbacks for Go

Go Report Card

General Usage

// Within your own app config package (or hey maybe right into your only .go file)

import "lyfecycle" // gotta have the package imported to use it

// Declare your lifecycle stages with unique integer values
const (
  LyfeCycleStage1 = iota
  LyfeCycleStage2
  LyfeCycleStage3
  LyfeCycleStage4
  LyfeCycleStage5
)

// during the soonest possible execution moment, register the full list of lifecycle stages
// module init() is about as early as you can get
func init() {
  // sequential stage list from the delcared stage IDs
  stageList := lyfecycle.StageIDsList{
    LyfeCycleStage1,
    LyfeCycleStage2,
    LyfeCycleStage3,
    LyfeCycleStage4,
    LyfeCycleStage5,
  }

  // declare this stage progression with the lyfecyle system
  lyfecycle.DefineStages(stageList)

  // register your callbacks as desired
  lyfecycle.RegisterEvent(LyfeCycleStage1, func() {
    // do something
  })
}

func main() {
  // sometime within your application, run all the stages (stages run in the order declared)
  lyfecycle.PerformAllStages() // all callbacks fire within the stage they belong and in the order they were registered
}

About

Simple application lifecycle via callbacks for Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages