Initial version
Project structure, api, discovery service, docker.
This commit is contained in:
56
cmd/server/main.go
Normal file
56
cmd/server/main.go
Normal file
@@ -0,0 +1,56 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user