feat: 添加生产环境部署工作流和相关文档
Deploy backend / deploy (push) Has been cancelled

This commit is contained in:
yuxuanhui
2026-09-29 19:17:46 +08:00
parent b0c62d461e
commit 34a2e3b751
5 changed files with 125 additions and 7 deletions
+12 -5
View File
@@ -29,15 +29,22 @@ func run() error {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
for _, key := range []string{"PGHOST", "PGDATABASE", "PGUSER", "PGPASSWORD"} {
if os.Getenv(key) == "" {
return fmt.Errorf("%s is required", key)
databaseURL := os.Getenv("DATABASE_URL")
if databaseURL == "" {
for _, key := range []string{"PGHOST", "PGDATABASE", "PGUSER", "PGPASSWORD"} {
if os.Getenv(key) == "" {
return fmt.Errorf("%s is required when DATABASE_URL is unset", key)
}
}
}
// Use libpq environment variables so passwords need no URL escaping.
pool, err := pgxpool.New(ctx, "")
// Production uses a URL; local development retains libpq environment variables.
pool, err := pgxpool.New(ctx, databaseURL)
if err != nil {
if databaseURL != "" {
// Parser errors can include the URL, so do not log the credential-bearing input.
return errors.New("configure database: invalid DATABASE_URL")
}
return fmt.Errorf("configure database: %w", err)
}
defer pool.Close()