You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lyfecycle - Simple application lifecycle via callbacks for Go
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 valuesconst (
LyfeCycleStage1=iotaLyfeCycleStage2LyfeCycleStage3LyfeCycleStage4LyfeCycleStage5
)
// during the soonest possible execution moment, register the full list of lifecycle stages// module init() is about as early as you can getfuncinit() {
// sequential stage list from the delcared stage IDsstageList:= lyfecycle.StageIDsList{
LyfeCycleStage1,
LyfeCycleStage2,
LyfeCycleStage3,
LyfeCycleStage4,
LyfeCycleStage5,
}
// declare this stage progression with the lyfecyle systemlyfecycle.DefineStages(stageList)
// register your callbacks as desiredlyfecycle.RegisterEvent(LyfeCycleStage1, func() {
// do something
})
}
funcmain() {
// 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
}