This repository has been archived on 2024-02-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
astontest/cmd/server/main.go
derfenix 7864272baa Initial version
Project structure, api, discovery service, docker.
2023-12-06 08:32:01 +03:00

57 lines
1005 B
Go

package main
import (
"context"
"fmt"
"os"
"os/signal"
"sync"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"git.derfenix.pro/fenix/astontest/internal/application"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)
defer cancel()
cfg, err := application.NewConfig(ctx)
if err != nil {
panic(err)
}
log, err := getLogger(cfg)
if err != nil {
panic(err)
}
app, err := application.NewApplication(&cfg, log)
if err != nil {
log.Error("new application", zap.Error(err))
return
}
wg := sync.WaitGroup{}
app.Start(ctx, &wg)
wg.Wait()
}
func getLogger(cfg application.Config) (*zap.Logger, error) {
logCfg := zap.NewProductionConfig()
logCfg.EncoderConfig.EncodeTime = zapcore.RFC3339TimeEncoder
if cfg.Debug {
logCfg.DisableStacktrace = false
logCfg.Level = zap.NewAtomicLevelAt(zapcore.DebugLevel)
}
log, err := logCfg.Build()
if err != nil {
return nil, fmt.Errorf("build logger: %w", err)
}
return log, nil
}