Files
archived-ackify-ce/internal/infrastructure/database/connection.go
T
Benjamin c1595ffe3e feat: migrate templates to embedded filesystem
- Move templates from web/templates/ to webtemplates/templates/
- Replace file-based template loading with Go embed
- Remove external template directory dependency from Dockerfile
- Add webtemplates package with embedded template functionality
- Include comprehensive tests for embedded templates
- Update server initialization to use new embedded template system

This change makes the application self-contained by embedding templates
directly in the binary, eliminating the need for external template files
at runtime.
2025-09-14 21:37:13 +02:00

34 lines
646 B
Go

package database
import (
"context"
"database/sql"
"fmt"
"time"
_ "github.com/lib/pq"
)
// Config holds database configuration
type Config struct {
DSN string
}
// InitDB initializes the database connection
func InitDB(ctx context.Context, config Config) (*sql.DB, error) {
db, err := sql.Open("postgres", config.DSN)
if err != nil {
return nil, fmt.Errorf("failed to open database: %w", err)
}
// Test connection with timeout
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
if err := db.PingContext(ctx); err != nil {
return nil, fmt.Errorf("failed to ping database: %w", err)
}
return db, nil
}