38 lines
789 B
Go
38 lines
789 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"log/slog"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"gitea.haiyihy.com/hy/chatapppay/internal/app"
|
|
"gitea.haiyihy.com/hy/chatapppay/internal/config"
|
|
)
|
|
|
|
func main() {
|
|
configPath := flag.String("config", config.DefaultPath, "path to config file")
|
|
flag.Parse()
|
|
|
|
cfg, err := config.Load(*configPath)
|
|
if err != nil {
|
|
slog.Error("load config failed", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
|
|
Level: slog.LevelInfo,
|
|
}))
|
|
|
|
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
application := app.New(cfg, logger)
|
|
if err := application.Run(ctx); err != nil {
|
|
logger.Error("application exited with error", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|