@@ -32,11 +32,13 @@ and global termination timeout for the whole application.
3232# ⚙️ Usage
3333
3434Get the library:
35+
3536``` bash
3637go get -u github.com/skovtunenko/graterm
3738```
3839
3940Import the library into the project:
41+
4042``` go
4143import (
4244 " github.com/skovtunenko/graterm"
@@ -45,13 +47,15 @@ import (
4547
4648Create a new instance of [ Terminator] ( https://pkg.go.dev/github.com/skovtunenko/graterm#Terminator ) and get an application context
4749that will be cancelled when one of the registered ` os.Signal ` s will occur:
50+
4851``` go
4952// create new Terminator instance:
5053terminator , appCtx := graterm.NewWithSignals (context.Background (), syscall.SIGINT , syscall.SIGTERM )
5154terminator.SetLogger (log.Default ()) // Optionally set the custom logger implementation instead of default NOOP one
5255```
5356
5457Optionally define [ Order] ( https://pkg.go.dev/github.com/skovtunenko/graterm#Order ) of components to be terminated at the end:
58+
5559``` go
5660const (
5761 HTTPServerTerminationOrder graterm.Order = 1
@@ -62,6 +66,7 @@ const (
6266```
6367
6468Register some termination [ Hooks] ( https://pkg.go.dev/github.com/skovtunenko/graterm#Hook ) with priorities:
69+
6570``` go
6671terminator.WithOrder (HTTPServerTerminationOrder).
6772 WithName (" HTTP Server" ). // setting a Name is optional and will be useful only if logger instance provided
@@ -73,6 +78,7 @@ terminator.WithOrder(HTTPServerTerminationOrder).
7378```
7479
7580Block main goroutine until the application receives one of the registered ` os.Signal ` s:
81+
7682``` go
7783if err := terminator.Wait (appCtx, 20 *time.Second ); err != nil {
7884 log.Printf (" graceful termination period was timed out: %+v " , err)
@@ -213,18 +219,22 @@ The full-fledged example located here: [example.go](https://github.com/skovtunen
213219
214220📖 Testing
215221-----------
222+
216223Unit-tests with code coverage:
224+
217225``` bash
218226make test
219227```
220228
221229Run linter:
230+
222231``` bash
223232make code-quality
224233```
225234
226235⚠️ LICENSE
227236-----------
237+
228238[ MIT] ( https://github.com/skovtunenko/graterm/blob/main/LICENSE )
229239
230240🕶️ AUTHORS
0 commit comments