73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
"os/signal"
|
|
"recipes/internal/config"
|
|
"syscall"
|
|
|
|
prettyLogger "github.com/charmbracelet/log"
|
|
)
|
|
|
|
const (
|
|
envLocal = "local"
|
|
envDev = "dev"
|
|
envProd = "prod"
|
|
)
|
|
|
|
//TODO
|
|
// cache
|
|
// http server
|
|
// app
|
|
// graceful sd
|
|
// tests
|
|
|
|
func main() {
|
|
// load config
|
|
cfg := config.MustLoad()
|
|
// init logger
|
|
log := setupLogger(cfg.Env)
|
|
log.Info("starting application", slog.String("env", cfg.Env))
|
|
log.Debug("debug messages are enabled")
|
|
log.Debug("Application config", slog.Any("config", fmt.Sprintf("%+v", *cfg)))
|
|
|
|
// init app (storage, cache, media storage)
|
|
|
|
// graceful shutdown
|
|
stop := make(chan os.Signal, 1)
|
|
signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT)
|
|
|
|
<-stop
|
|
|
|
log.Info("stopping application...")
|
|
|
|
// application.GRPCSrv.Stop()
|
|
|
|
log.Info("application stopped")
|
|
}
|
|
|
|
func setupLogger(env string) *slog.Logger {
|
|
var log *slog.Logger
|
|
|
|
switch env {
|
|
case envLocal:
|
|
// log = slog.New(
|
|
// slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}),
|
|
// )
|
|
handler := prettyLogger.NewWithOptions(os.Stdout, prettyLogger.Options{Level: prettyLogger.DebugLevel})
|
|
log = slog.New(handler)
|
|
case envDev:
|
|
log = slog.New(
|
|
slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}),
|
|
)
|
|
case envProd:
|
|
log = slog.New(
|
|
slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}),
|
|
)
|
|
}
|
|
|
|
return log
|
|
}
|