This repository has been archived on 2023-12-05. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
protect_trans_info/cmd/service/main.go
2023-08-24 23:40:46 +03:00

57 lines
902 B
Go

package main
import (
"context"
"fmt"
"os"
"os/signal"
"sync"
"go.uber.org/zap"
"git.derfenix.pro/fenix/protect_trans_info/application"
)
func main() {
cfg, err := application.NewConfig()
if err != nil {
panic(fmt.Sprintf("load config: %v", err))
}
var logger *zap.Logger
switch cfg.Devel {
case true:
logger, err = zap.NewDevelopment()
case false:
logger, err = zap.NewProduction()
}
if err != nil {
panic(fmt.Sprintf("init logger: %v", err))
}
ctx, cancel := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)
defer cancel()
app, err := application.NewApplication(ctx, cfg, logger)
if err != nil {
logger.Fatal("create application failed", zap.Error(err))
}
wg := sync.WaitGroup{}
go func() {
<-ctx.Done()
app.Stop(&wg)
}()
app.Start(&wg)
wg.Wait()
// Context did not stop the application
if ctx.Err() == nil {
os.Exit(2)
}
}