-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (43 loc) · 1.03 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
56
package main
import (
"context"
"os"
"os/signal"
"syscall"
flag "github.com/spf13/pflag"
"github.com/thejerf/suture/v4"
"github.com/tpl-x/echo/internal/config"
"go.uber.org/zap"
)
var (
configPath string
)
func init() {
flag.StringVarP(&configPath, "config", "c", "config.yaml", "start using config file")
}
func main() {
flag.Parse()
appConfig, err := config.LoadFromFile(configPath)
if err != nil {
panic("failed to load config")
}
logger, _ := zap.NewProduction()
defer logger.Sync()
sup := suture.NewSimple("echoWebServer")
app := wireApp(appConfig)
sup.Add(app)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Set up signal handling
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigChan
logger.Info("Received signal", zap.String("signal", sig.String()))
cancel()
}()
if err := sup.Serve(ctx); err != nil {
logger.Error("Server is about to shutdown", zap.Error(err))
}
logger.Info("Server shutdown complete")
}