ci: add golangci-lint config and fix formatting
- Add .golangci.yml with minimal linters (govet, ineffassign) - Run gofmt -s and goimports on all files to fix formatting - Disable fieldalignment and copylocks checks in govet
This commit is contained in:
@@ -23,7 +23,7 @@ func NewDiskSpaceCache(ttl time.Duration) *DiskSpaceCache {
|
||||
if ttl <= 0 {
|
||||
ttl = 30 * time.Second // Default 30 second cache
|
||||
}
|
||||
|
||||
|
||||
return &DiskSpaceCache{
|
||||
cache: make(map[string]*cacheEntry),
|
||||
cacheTTL: ttl,
|
||||
@@ -40,17 +40,17 @@ func (c *DiskSpaceCache) Get(path string) *DiskSpaceCheck {
|
||||
}
|
||||
}
|
||||
c.mu.RUnlock()
|
||||
|
||||
|
||||
// Cache miss or expired - perform new check
|
||||
check := CheckDiskSpace(path)
|
||||
|
||||
|
||||
c.mu.Lock()
|
||||
c.cache[path] = &cacheEntry{
|
||||
check: check,
|
||||
timestamp: time.Now(),
|
||||
}
|
||||
c.mu.Unlock()
|
||||
|
||||
|
||||
return check
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func (c *DiskSpaceCache) Clear() {
|
||||
func (c *DiskSpaceCache) Cleanup() {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
|
||||
now := time.Now()
|
||||
for path, entry := range c.cache {
|
||||
if now.Sub(entry.timestamp) >= c.cacheTTL {
|
||||
@@ -80,4 +80,4 @@ var globalDiskCache = NewDiskSpaceCache(30 * time.Second)
|
||||
// CheckDiskSpaceCached performs cached disk space check
|
||||
func CheckDiskSpaceCached(path string) *DiskSpaceCheck {
|
||||
return globalDiskCache.Get(path)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func CheckDiskSpace(path string) *DiskSpaceCheck {
|
||||
func CheckDiskSpaceForRestore(path string, archiveSize int64) *DiskSpaceCheck {
|
||||
check := CheckDiskSpace(path)
|
||||
requiredBytes := uint64(archiveSize) * 4 // Account for decompression
|
||||
|
||||
|
||||
// Override status based on required space
|
||||
if check.AvailableBytes < requiredBytes {
|
||||
check.Critical = true
|
||||
@@ -64,7 +64,7 @@ func CheckDiskSpaceForRestore(path string, archiveSize int64) *DiskSpaceCheck {
|
||||
check.Warning = true
|
||||
check.Sufficient = false
|
||||
}
|
||||
|
||||
|
||||
return check
|
||||
}
|
||||
|
||||
@@ -134,7 +134,3 @@ func EstimateBackupSize(databaseSize uint64, compressionLevel int) uint64 {
|
||||
// Add 10% buffer for metadata, indexes, etc.
|
||||
return uint64(float64(estimated) * 1.1)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ func CheckDiskSpace(path string) *DiskSpaceCheck {
|
||||
func CheckDiskSpaceForRestore(path string, archiveSize int64) *DiskSpaceCheck {
|
||||
check := CheckDiskSpace(path)
|
||||
requiredBytes := uint64(archiveSize) * 4 // Account for decompression
|
||||
|
||||
|
||||
// Override status based on required space
|
||||
if check.AvailableBytes < requiredBytes {
|
||||
check.Critical = true
|
||||
@@ -64,7 +64,7 @@ func CheckDiskSpaceForRestore(path string, archiveSize int64) *DiskSpaceCheck {
|
||||
check.Warning = true
|
||||
check.Sufficient = false
|
||||
}
|
||||
|
||||
|
||||
return check
|
||||
}
|
||||
|
||||
@@ -108,4 +108,4 @@ func FormatDiskSpaceMessage(check *DiskSpaceCheck) string {
|
||||
}
|
||||
|
||||
return msg
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func CheckDiskSpace(path string) *DiskSpaceCheck {
|
||||
func CheckDiskSpaceForRestore(path string, archiveSize int64) *DiskSpaceCheck {
|
||||
check := CheckDiskSpace(path)
|
||||
requiredBytes := uint64(archiveSize) * 4 // Account for decompression
|
||||
|
||||
|
||||
// Override status based on required space
|
||||
if check.AvailableBytes < requiredBytes {
|
||||
check.Critical = true
|
||||
@@ -47,7 +47,7 @@ func CheckDiskSpaceForRestore(path string, archiveSize int64) *DiskSpaceCheck {
|
||||
check.Warning = true
|
||||
check.Sufficient = false
|
||||
}
|
||||
|
||||
|
||||
return check
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ func CheckDiskSpace(path string) *DiskSpaceCheck {
|
||||
// If no volume, try current directory
|
||||
vol = "."
|
||||
}
|
||||
|
||||
|
||||
var freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes uint64
|
||||
|
||||
// Call Windows API
|
||||
@@ -73,7 +73,7 @@ func CheckDiskSpace(path string) *DiskSpaceCheck {
|
||||
func CheckDiskSpaceForRestore(path string, archiveSize int64) *DiskSpaceCheck {
|
||||
check := CheckDiskSpace(path)
|
||||
requiredBytes := uint64(archiveSize) * 4 // Account for decompression
|
||||
|
||||
|
||||
// Override status based on required space
|
||||
if check.AvailableBytes < requiredBytes {
|
||||
check.Critical = true
|
||||
@@ -83,7 +83,7 @@ func CheckDiskSpaceForRestore(path string, archiveSize int64) *DiskSpaceCheck {
|
||||
check.Warning = true
|
||||
check.Sufficient = false
|
||||
}
|
||||
|
||||
|
||||
return check
|
||||
}
|
||||
|
||||
@@ -128,4 +128,3 @@ func FormatDiskSpaceMessage(check *DiskSpaceCheck) string {
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
|
||||
// Compiled regex patterns for robust error matching
|
||||
var errorPatterns = map[string]*regexp.Regexp{
|
||||
"already_exists": regexp.MustCompile(`(?i)(already exists|duplicate key|unique constraint|relation.*exists)`),
|
||||
"disk_full": regexp.MustCompile(`(?i)(no space left|disk.*full|write.*failed.*space|insufficient.*space)`),
|
||||
"lock_exhaustion": regexp.MustCompile(`(?i)(max_locks_per_transaction|out of shared memory|lock.*exhausted|could not open large object)`),
|
||||
"syntax_error": regexp.MustCompile(`(?i)syntax error at.*line \d+`),
|
||||
"already_exists": regexp.MustCompile(`(?i)(already exists|duplicate key|unique constraint|relation.*exists)`),
|
||||
"disk_full": regexp.MustCompile(`(?i)(no space left|disk.*full|write.*failed.*space|insufficient.*space)`),
|
||||
"lock_exhaustion": regexp.MustCompile(`(?i)(max_locks_per_transaction|out of shared memory|lock.*exhausted|could not open large object)`),
|
||||
"syntax_error": regexp.MustCompile(`(?i)syntax error at.*line \d+`),
|
||||
"permission_denied": regexp.MustCompile(`(?i)(permission denied|must be owner|access denied)`),
|
||||
"connection_failed": regexp.MustCompile(`(?i)(connection refused|could not connect|no pg_hba\.conf entry)`),
|
||||
"version_mismatch": regexp.MustCompile(`(?i)(version mismatch|incompatible|unsupported version)`),
|
||||
@@ -135,9 +135,9 @@ func ClassifyError(errorMsg string) *ErrorClassification {
|
||||
}
|
||||
|
||||
// Lock exhaustion errors
|
||||
if strings.Contains(lowerMsg, "max_locks_per_transaction") ||
|
||||
strings.Contains(lowerMsg, "out of shared memory") ||
|
||||
strings.Contains(lowerMsg, "could not open large object") {
|
||||
if strings.Contains(lowerMsg, "max_locks_per_transaction") ||
|
||||
strings.Contains(lowerMsg, "out of shared memory") ||
|
||||
strings.Contains(lowerMsg, "could not open large object") {
|
||||
return &ErrorClassification{
|
||||
Type: "critical",
|
||||
Category: "locks",
|
||||
@@ -173,9 +173,9 @@ func ClassifyError(errorMsg string) *ErrorClassification {
|
||||
}
|
||||
|
||||
// Connection errors
|
||||
if strings.Contains(lowerMsg, "connection refused") ||
|
||||
strings.Contains(lowerMsg, "could not connect") ||
|
||||
strings.Contains(lowerMsg, "no pg_hba.conf entry") {
|
||||
if strings.Contains(lowerMsg, "connection refused") ||
|
||||
strings.Contains(lowerMsg, "could not connect") ||
|
||||
strings.Contains(lowerMsg, "no pg_hba.conf entry") {
|
||||
return &ErrorClassification{
|
||||
Type: "critical",
|
||||
Category: "network",
|
||||
|
||||
@@ -26,4 +26,4 @@ func formatBytes(bytes uint64) string {
|
||||
exp++
|
||||
}
|
||||
return fmt.Sprintf("%.1f %ciB", float64(bytes)/float64(div), "KMGTPE"[exp])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user