-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (51 loc) · 1.22 KB
/
main.go
File metadata and controls
64 lines (51 loc) · 1.22 KB
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
57
58
59
60
61
62
63
64
package main
import (
"context"
"os"
"os/signal"
"syscall"
flag "github.com/spf13/pflag"
"github.com/tpl-x/echo/internal/biz"
"github.com/tpl-x/echo/internal/config"
"github.com/tpl-x/echo/internal/data"
"github.com/tpl-x/echo/internal/handler"
"github.com/tpl-x/echo/internal/pkg/logger"
"go.uber.org/fx"
"go.uber.org/zap"
)
var (
configPath string
)
func init() {
flag.StringVarP(&configPath, "config", "c", "config.yaml", "start using config file")
}
func main() {
flag.Parse()
fxApp := fx.New(
fx.Provide(config.ProvideConfig(configPath)),
logger.Module,
data.Module,
biz.Module,
handler.Module,
fx.Provide(NewApp),
fx.NopLogger,
)
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
zap.L().Info("Received signal", zap.String("signal", sig.String()))
cancel()
}()
if err := fxApp.Start(ctx); err != nil {
panic("failed to start fx app")
}
<-ctx.Done()
if err := fxApp.Stop(context.Background()); err != nil {
zap.L().Error("Server shutdown error", zap.Error(err))
}
zap.L().Info("Server shutdown complete")
}