mirror of
https://github.com/btouchard/ackify-ce.git
synced 2026-02-28 10:48:47 -06:00
c1595ffe3e
- 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.
34 lines
646 B
Go
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
|
|
}
|