https://github.com/henrikfricke/go-lifecycle
life cycle manager for Go
https://github.com/henrikfricke/go-lifecycle
cycle go golang library life lifecycle task-runner
Last synced: about 1 month ago
JSON representation
life cycle manager for Go
- Host: GitHub
- URL: https://github.com/henrikfricke/go-lifecycle
- Owner: HenrikFricke
- License: mit
- Created: 2017-07-12T16:27:54.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-13T19:54:53.000Z (almost 9 years ago)
- Last Synced: 2024-01-27T12:55:36.119Z (over 2 years ago)
- Topics: cycle, go, golang, library, life, lifecycle, task-runner
- Language: Go
- Homepage: http://gopkg.in/henrikfricke/go-lifecycle.v1
- Size: 8.79 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# go-lifecycle
## Usage
This project uses [gopkg](http://labix.org/gopkg.in) to handle versioning. Find more information about how to install and where to find the API documentation [here](http://gopkg.in/henrikfricke/go-lifecycle.v1).
## About the project
This project is inspired by the [Lifecycle](https://serverless.com/blog/writing-serverless-plugins/#lifecycle-events) of the [Serverless Framework](https://serverless.com/). The Serverless CLI handles plugins, which are able to hook before or after a process. Every plugin is also a process in the lifecycle, so other plugins can hook before or after a plugin as well. I really liked the way how Serverless build the plugin architecture and I wanted to think about how to achieve this process management in Go.
## Concept
The idea is to creeate a sequence of tasks and execute them afterwards. So we have something like a queue with tasks. The tasks will be executed with the [FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)) method. But you can also have the special behaviour of hooks: You can add a pre or post hook to every task and also to every hook (because technically every hook is also a task).
## Example
Let's take a look to a simple example:
```go
package main
import (
"fmt"
glc "github.com/HenrikFricke/go-lifecycle"
)
const (
task1Name glc.TaskName = "task_one"
task2Name = "task_two"
preHook = "pre_hook"
)
func printOut(luggage interface{}) {
fmt.Println("I'am a task")
}
func printOutHook(luggage interface{}) {
fmt.Println("I'am a hook")
}
func main() {
lifecycle := glc.NewLifecycle()
lifecycle.AddTask(task1Name, printOut)
lifecycle.AddTask(task2Name, printOut)
lifecycle.AddPreHook(task2Name, preHook, printOutHook)
lifecycle.Execute(nil)
}
```
We define here two tasks and one pre hook for the second task, the output of this example is:
```bash
I'am a task
I'am a hook
I'am a task
```
You can find a more complex example in the `example` folder. You can clone this repository on your local machine and execute the example with `go run example/example.go`.