Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust features section in the README.md #78

Merged
merged 2 commits into from
Aug 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

Provides primitives to perform ordered **GRA**ceful **TERM**ination (aka shutdown) in Go application.

# Description
# ⚡ ️️Description

Library provides fluent methods to register ordered application termination (aka shutdown) [hooks](https://pkg.go.dev/github.com/skovtunenko/graterm#Hook),
and block the main goroutine until the registered `os.Signal` will occur.
Expand All @@ -21,7 +21,14 @@ same [Order](https://pkg.go.dev/github.com/skovtunenko/graterm#Order) will be ex
It is possible to set individual timeouts for each registered termination [hook](https://pkg.go.dev/github.com/skovtunenko/graterm#Hook)
and global termination timeout for the whole application.

# Usage
# 🎯 Features

* Dependency only on a standard Go library (except tests).
* Component-agnostic (can be adapted to any 3rd party technology).
* Clean and tested code: 100% test coverage, including goroutine leak tests.
* Rich set of examples.

# ⚙️ Usage

Get the library:
```bash
Expand Down Expand Up @@ -56,7 +63,7 @@ const (
Register some termination [Hooks](https://pkg.go.dev/github.com/skovtunenko/graterm#Hook) with priorities:
```go
terminator.WithOrder(HTTPServerTerminationOrder).
WithName("HTTP Server").
WithName("HTTP Server"). // setting a Name is optional and will be useful only if logger instance provided
Register(1*time.Second, func(ctx context.Context) {
if err := httpServer.Shutdown(ctx); err != nil {
log.Printf("shutdown HTTP Server: %+v\n", err)
Expand All @@ -71,18 +78,11 @@ if err := terminator.Wait(appCtx, 20*time.Second); err != nil {
}
```

# Features

* dependency only on a standard Go library
* Component-agnostic (can be adapted to any 3rd party technology)
* 100% test coverage, including goroutine leak tests
* Rich set of examples

# Versioning
# 👀 Versioning

The library follows SemVer policy. With the release of v1.0.0 the public API is stable.

# Example
# 📚 Example

Each public function has example attached to it. Here is the simple one:

Expand All @@ -108,10 +108,11 @@ func main() {

// create new Terminator instance:
terminator, appCtx := graterm.NewWithSignals(context.Background(), syscall.SIGINT, syscall.SIGTERM)
terminator.SetLogger(log.Default()) // Optional step

// Register HTTP Server termination hook:
terminator.WithOrder(HTTPServerTerminationOrder).
WithName("HTTP Server").
WithName("HTTP Server"). // setting a Name is optional and will be useful only if logger instance provided
Register(1*time.Second, func(ctx context.Context) {
log.Println("terminating HTTP Server...")
defer log.Println("...HTTP Server terminated")
Expand All @@ -126,7 +127,7 @@ func main() {

// Register Database termination hook:
terminator.WithOrder(DBTerminationOrder).
WithName("DB").
WithName("DB"). // setting a Name is optional and will be useful only if logger instance provided
Register(1*time.Second, func(ctx context.Context) {
log.Println("terminating DB...")
defer log.Println("...DB terminated")
Expand All @@ -147,7 +148,7 @@ func main() {
}
```

Integration with HTTP server
💡 Integration with HTTP server
-----------

The library doesn't have out of the box support to start/terminate the HTTP server, but that's easy to handle:
Expand All @@ -173,11 +174,13 @@ func main() {

// create new Terminator instance:
terminator, appCtx := graterm.NewWithSignals(context.Background(), syscall.SIGINT, syscall.SIGTERM)
terminator.SetLogger(log.Default()) // Optional step

// Create an HTTP Server and add one simple handler into it:
httpServer := &http.Server{
Addr: ":8080",
Handler: http.DefaultServeMux,
ReadHeaderTimeout: 60 * time.Second, // fix for potential Slowloris Attack
Addr: ":8080",
Handler: http.DefaultServeMux,
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "hello, world!")
Expand All @@ -192,7 +195,7 @@ func main() {

// Register HTTP Server termination hook:
terminator.WithOrder(HTTPServerTerminationOrder).
WithName("HTTPServer").
WithName("HTTPServer"). // setting a Name is optional and will be useful only if logger instance provided
Register(10*time.Second, func(ctx context.Context) {
if err := httpServer.Shutdown(ctx); err != nil {
log.Printf("shutdown HTTP Server: %+v\n", err)
Expand All @@ -208,7 +211,7 @@ func main() {

The full-fledged example located here: [example.go](https://github.com/skovtunenko/graterm/blob/main/internal/example/example.go)

Testing
📖 Testing
-----------
Unit-tests with code coverage:
```bash
Expand All @@ -220,13 +223,12 @@ Run linter:
make code-quality
```

LICENSE
⚠️ LICENSE
-----------
MIT
[MIT](https://github.com/skovtunenko/graterm/blob/main/LICENSE)

AUTHORS
🕶️ AUTHORS
-----------

Sergiy Kovtunenko <@skovtunenko>

Oleksandr Halushchak <ohalushchak@exadel.com>
* [Sergiy Kovtunenko](https://github.com/skovtunenko)
* [Oleksandr Halushchak](ohalushchak@exadel.com)