-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
35 lines (30 loc) · 1.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main // github.com/mikaponics/mikapod-soil/cmd/reader
import (
"os"
"os/signal"
"syscall"
"fmt"
"github.com/mikaponics/mikapod-soil-poller/configs"
"github.com/mikaponics/mikapod-soil-poller/internal"
)
func main() {
app := internal.InitMikapodPoller(configs.MikapodStorageServiceAddress, configs.MikapodSoilReaderServiceAddress)
// DEVELOPERS CODE:
// The following code will create an anonymous goroutine which will have a
// blocking chan `sigs`. This blocking chan will only unblock when the
// golang app receives a termination command; therfore the anyomous
// goroutine will run and terminate our running application.
//
// Special Thanks:
// (1) https://gobyexample.com/signals
// (2) https://guzalexander.com/2017/05/31/gracefully-exit-server-in-go.html
//
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs // Block execution until signal from terminal gets triggered here.
fmt.Println("Starting graceful shut down now.")
app.StopMainRuntimeLoop()
}()
app.RunMainRuntimeLoop()
}