Migrate all log.Printf/log.Fatalf to log/slog with structured key-value attributes per bible go-logging contract. - Add withRequestID middleware: generates crypto/rand 8-byte hex ID per request, sets X-Request-ID response header, injects into context - withErrorLogging uses slog with request_id from context - writeError internal log calls migrated to slog.Error/slog.Warn - All handler log calls in api, ingest, history packages use slog - cmd/reanimator-api configures slog.NewTextHandler(os.Stdout) at startup - cmd/reanimator-migrate, cmd/reanimator-reset migrated to slog Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
998 B
Go
48 lines
998 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"reanimator/internal/config"
|
|
"reanimator/internal/repository/migrate"
|
|
)
|
|
|
|
func main() {
|
|
directionFlag := flag.String("direction", string(migrate.Up), "migration direction: up|down")
|
|
dryRun := flag.Bool("dry-run", true, "print discovered migrations only")
|
|
flag.Parse()
|
|
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
slog.Error("load config failed", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
direction := migrate.Direction(*directionFlag)
|
|
if direction != migrate.Up && direction != migrate.Down {
|
|
slog.Error("invalid direction", "direction", *directionFlag)
|
|
os.Exit(1)
|
|
}
|
|
|
|
runner := migrate.Runner{Dir: cfg.MigrationsDir}
|
|
migrations, err := runner.Load(direction)
|
|
if err != nil {
|
|
slog.Error("load migrations failed", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
for _, migration := range migrations {
|
|
fmt.Println(migration.Name)
|
|
}
|
|
|
|
if *dryRun {
|
|
return
|
|
}
|
|
|
|
slog.Error("execution mode is not implemented yet; keep dry-run=true for now")
|
|
os.Exit(1)
|
|
}
|