Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/novln/lemon
An engine to manage your components lifecycle.
https://github.com/novln/lemon
Last synced: about 1 month ago
JSON representation
An engine to manage your components lifecycle.
- Host: GitHub
- URL: https://github.com/novln/lemon
- Owner: novln
- License: mit
- Created: 2016-10-20T15:18:12.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-06T20:38:25.000Z (over 5 years ago)
- Last Synced: 2024-06-20T20:04:41.575Z (5 months ago)
- Language: Go
- Homepage:
- Size: 931 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lemon
[![Documentation][godoc-img]][godoc-url]
![License][license-img]
[![Build Status][travis-img]][travis-url]
[![Coverage Status][coverage-img]][coverage-url]
[![Report Status][goreport-img]][goreport-url]An engine to manage your components lifecycle.
[![Lemon][lemon-img]][lemon-url]
## Introduction
Lemon is an engine that manage your components lifecycle using a startup and shutdown mechanism.
It will start every registered hook _(or daemon, service, etc...)_ and block until it receives a signal
(**SIGINT**, **SIGTERM** and **SIGQUIT** for example) or when a parent context is terminated...> **NOTE:** startup and shutdown procedure will be executed in separated goroutine: so be very careful with
any race conditions or deadlocks.## Example
```go
package mainimport (
"context"
"fmt"
"os"
"time""github.com/novln/lemon"
)// Let's define a simple Ping hook...
type Ping struct {}// Start will be executed when lemon's engine will try to start this Hook.
// Your hook can perfectly use the given context (see example), or any blocking operation...
func (p *Ping) Start(ctx context.Context) error {fmt.Println("[ping] Start")
for {
select {
case <-ctx.Done():
return nil
case <-time.After(2 * time.Second):
fmt.Println("[ping] Echo Request")
}
}
}// However, if you don't use <-ctx.Done(), you must cancel your blocking operation in Stop.
func (p *Ping) Stop(ctx context.Context) error {
fmt.Println("[ping] Stop")
return nil
}func main() {
timeout := 5 * time.Second
ctx := context.Background()engine, err := lemon.New(ctx, lemon.Timeout(timeout), lemon.Logger(func(err error) {
fmt.Fprintln(os.Stderr, err)
}))if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(255)
}engine.Register(&Ping{})
engine.Start()}
```
## Versioning or Vendoring
Expect compatibility break from `master` branch.
Using [Go dependency management tool](https://github.com/golang/dep) is **highly recommended**.
> **NOTE:** semver tags or branches could be provided, if needed.
## License
This is Free Software, released under the [`MIT License`](LICENSE).
[lemon-url]: https://github.com/novln/lemon
[lemon-img]: https://raw.githubusercontent.com/novln/lemon/master/lemon.png
[godoc-url]: https://godoc.org/github.com/novln/lemon
[godoc-img]: https://godoc.org/github.com/novln/lemon?status.svg
[license-img]: https://img.shields.io/badge/license-MIT-blue.svg
[travis-url]: https://travis-ci.org/novln/lemon
[travis-img]: https://travis-ci.org/novln/lemon.svg?branch=master
[coverage-url]: https://codecov.io/gh/novln/lemon
[coverage-img]: https://codecov.io/gh/novln/lemon/branch/master/graph/badge.svg
[goreport-url]: https://goreportcard.com/report/novln/lemon
[goreport-img]: https://goreportcard.com/badge/novln/lemon