style: Apply code formatting with go fmt
- Run 'make format' to ensure all Go code follows standard formatting - Maintains consistent code style across the entire codebase - No functional changes, only whitespace and formatting improvements
This commit is contained in:
parent
4fd0846127
commit
2bffa2c418
19 changed files with 543 additions and 527 deletions
|
|
@ -19,35 +19,35 @@ import (
|
|||
|
||||
// Database represents the main database connection and operations
|
||||
type Database struct {
|
||||
conn *sql.DB
|
||||
config *Config
|
||||
migrator *Migrator
|
||||
callsign *CallsignManager
|
||||
history *HistoryManager
|
||||
conn *sql.DB
|
||||
config *Config
|
||||
migrator *Migrator
|
||||
callsign *CallsignManager
|
||||
history *HistoryManager
|
||||
}
|
||||
|
||||
// Config holds database configuration options
|
||||
type Config struct {
|
||||
// Database file path (auto-resolved if empty)
|
||||
Path string `json:"path"`
|
||||
|
||||
|
||||
// Data retention settings
|
||||
MaxHistoryDays int `json:"max_history_days"` // 0 = unlimited
|
||||
MaxHistoryDays int `json:"max_history_days"` // 0 = unlimited
|
||||
BackupOnUpgrade bool `json:"backup_on_upgrade"`
|
||||
|
||||
|
||||
// Connection settings
|
||||
MaxOpenConns int `json:"max_open_conns"` // Default: 10
|
||||
MaxIdleConns int `json:"max_idle_conns"` // Default: 5
|
||||
ConnMaxLifetime time.Duration `json:"conn_max_lifetime"` // Default: 1 hour
|
||||
|
||||
|
||||
// Maintenance settings
|
||||
VacuumInterval time.Duration `json:"vacuum_interval"` // Default: 24 hours
|
||||
VacuumInterval time.Duration `json:"vacuum_interval"` // Default: 24 hours
|
||||
CleanupInterval time.Duration `json:"cleanup_interval"` // Default: 1 hour
|
||||
|
||||
|
||||
// Compression settings
|
||||
EnableCompression bool `json:"enable_compression"` // Enable automatic compression
|
||||
CompressionLevel int `json:"compression_level"` // Compression level (1-9, default: 6)
|
||||
PageSize int `json:"page_size"` // SQLite page size (default: 4096)
|
||||
EnableCompression bool `json:"enable_compression"` // Enable automatic compression
|
||||
CompressionLevel int `json:"compression_level"` // Compression level (1-9, default: 6)
|
||||
PageSize int `json:"page_size"` // SQLite page size (default: 4096)
|
||||
}
|
||||
|
||||
// AircraftHistoryRecord represents a stored aircraft position update
|
||||
|
|
@ -93,18 +93,18 @@ type AirlineRecord struct {
|
|||
|
||||
// AirportRecord represents embedded airport data from OpenFlights
|
||||
type AirportRecord struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
City string `json:"city"`
|
||||
Country string `json:"country"`
|
||||
IATA string `json:"iata"`
|
||||
ICAO string `json:"icao"`
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
Altitude int `json:"altitude"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
City string `json:"city"`
|
||||
Country string `json:"country"`
|
||||
IATA string `json:"iata"`
|
||||
ICAO string `json:"icao"`
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
Altitude int `json:"altitude"`
|
||||
TimezoneOffset float64 `json:"timezone_offset"`
|
||||
DST string `json:"dst"`
|
||||
Timezone string `json:"timezone"`
|
||||
DST string `json:"dst"`
|
||||
Timezone string `json:"timezone"`
|
||||
}
|
||||
|
||||
// DatabaseError represents database operation errors
|
||||
|
|
@ -131,7 +131,7 @@ func NewDatabase(config *Config) (*Database, error) {
|
|||
if config == nil {
|
||||
config = DefaultConfig()
|
||||
}
|
||||
|
||||
|
||||
// Resolve database path
|
||||
dbPath, err := ResolveDatabasePath(config.Path)
|
||||
if err != nil {
|
||||
|
|
@ -142,7 +142,7 @@ func NewDatabase(config *Config) (*Database, error) {
|
|||
}
|
||||
}
|
||||
config.Path = dbPath
|
||||
|
||||
|
||||
// Open database connection
|
||||
conn, err := sql.Open("sqlite3", buildConnectionString(dbPath))
|
||||
if err != nil {
|
||||
|
|
@ -152,12 +152,12 @@ func NewDatabase(config *Config) (*Database, error) {
|
|||
Retryable: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Configure connection pool
|
||||
conn.SetMaxOpenConns(config.MaxOpenConns)
|
||||
conn.SetMaxIdleConns(config.MaxIdleConns)
|
||||
conn.SetConnMaxLifetime(config.ConnMaxLifetime)
|
||||
|
||||
|
||||
// Test connection
|
||||
if err := conn.Ping(); err != nil {
|
||||
conn.Close()
|
||||
|
|
@ -167,17 +167,17 @@ func NewDatabase(config *Config) (*Database, error) {
|
|||
Retryable: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
db := &Database{
|
||||
conn: conn,
|
||||
config: config,
|
||||
}
|
||||
|
||||
|
||||
// Initialize components
|
||||
db.migrator = NewMigrator(conn)
|
||||
db.callsign = NewCallsignManager(conn)
|
||||
db.history = NewHistoryManager(conn, config.MaxHistoryDays)
|
||||
|
||||
|
||||
return db, nil
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +191,7 @@ func (db *Database) Initialize() error {
|
|||
Retryable: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Load embedded OpenFlights data if not already loaded
|
||||
if err := db.callsign.LoadEmbeddedData(); err != nil {
|
||||
return &DatabaseError{
|
||||
|
|
@ -200,7 +200,7 @@ func (db *Database) Initialize() error {
|
|||
Retryable: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -240,7 +240,6 @@ func (db *Database) Health() error {
|
|||
return db.conn.Ping()
|
||||
}
|
||||
|
||||
|
||||
// DefaultConfig returns the default database configuration
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
|
|
@ -258,4 +257,4 @@ func DefaultConfig() *Config {
|
|||
// buildConnectionString creates SQLite connection string with optimizations
|
||||
func buildConnectionString(path string) string {
|
||||
return fmt.Sprintf("%s?_journal_mode=WAL&_synchronous=NORMAL&_cache_size=-64000&_temp_store=MEMORY&_foreign_keys=ON", path)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue