Исправить замечания ревью кода: убрать повтор в AppendOnce за счёт запаса у чистки ключей, вынести MessagePayload и SameContent, принять X-Request-Id от балансировщика, упростить фоновые задачи сервера, сократить комментарии

This commit is contained in:
2026-11-04 12:19:49 +03:00
parent c9d0f73221
commit 7fbd781ca3
25 changed files with 207 additions and 247 deletions
+3 -12
View File
@@ -1,6 +1,5 @@
// Command migrate applies the embedded schema migrations once and exits. It
// runs as a one-shot service before the API replicas start, so the replicas
// never race each other over the schema and need no rights to change it.
// Command migrate applies the embedded schema migrations once and exits, so
// the API replicas never race each other over the schema.
package main
import (
@@ -24,7 +23,7 @@ func main() {
fmt.Fprintln(os.Stderr, "configuration error:", err)
os.Exit(2)
}
log := newLogger(cfg)
log := cfg.NewLogger()
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer stop()
@@ -48,11 +47,3 @@ func run(ctx context.Context, log *slog.Logger, cfg config.Migrate) error {
log.Info("migrations applied", "applied_migrations", applied)
return nil
}
func newLogger(cfg config.Migrate) *slog.Logger {
opts := &slog.HandlerOptions{Level: cfg.LogLevel}
if cfg.Env == "dev" {
return slog.New(slog.NewTextHandler(os.Stdout, opts))
}
return slog.New(slog.NewJSONHandler(os.Stdout, opts))
}