/
main.go
55 lines (42 loc) · 1.22 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"
"github.com/antmordel/getting-started-service/foundation/logger"
"go.uber.org/zap"
"go.uber.org/automaxprocs/maxprocs"
)
func main() {
// Construct the application logger.
log, err := logger.New("SALES-API")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer log.Sync()
// Perform the startup and shutdown sequence.
if err := run(log); err != nil {
log.Errorw("startup", "ERROR", err)
os.Exit(1)
}
}
func run(log *zap.SugaredLogger) error {
// =========================================================================
// GOMAXPROCS
// Set the correct number of threads for the service
// based on what is available either by the machine or quotas.
if _, err := maxprocs.Set(); err != nil {
return fmt.Errorf("maxprocs: %w", err)
}
log.Infow("startup", "GOMAXPROCS", runtime.GOMAXPROCS(0))
// =========================================================================
shutdown := make(chan os.Signal, 1)
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)
sig := <-shutdown
log.Infow("shutdown", "status", "shutdown started", "signal", sig)
defer log.Infow("shutdown", "status", "shutdown complete", "signal", sig)
return nil
}