Documentation
¶
Index ¶
- func CombineCleanResults(results []domain.CleanResult) domain.CleanResult
- func ExtractBytesFromCleanResult(cleanResult result.Result[domain.CleanResult]) result.Result[int64]
- func NewCleanResult(strategy domain.CleanStrategyType, itemsRemoved int, freedBytes int64) domain.CleanResult
- func NewCleanResultWithFailures(strategy domain.CleanStrategyType, itemsRemoved, itemsFailed int, ...) domain.CleanResult
- func NewCleanResultWithSizeEstimate(strategy domain.CleanStrategyType, itemsRemoved int, freedBytes int64, ...) domain.CleanResult
- func NewCleanResultWithTiming(strategy domain.CleanStrategyType, itemsRemoved int, freedBytes int64, ...) domain.CleanResult
- func NewCleanResultWithTimingAndSize(strategy domain.CleanStrategyType, itemsRemoved, itemsFailed int, ...) domain.CleanResult
- func NewScanResult(totalBytes int64, totalItems int, scannedPaths []string, ...) domain.ScanResult
- func ToCleanResult(bytesResult result.Result[int64]) result.Result[domain.CleanResult]
- func ToCleanResultFromError(err error) result.Result[domain.CleanResult]
- func ToCleanResultFromItems(itemsRemoved int, bytesResult result.Result[int64], ...) result.Result[domain.CleanResult]
- func ToCleanResultWithStrategy(bytesResult result.Result[int64], strategy domain.CleanStrategyType) result.Result[domain.CleanResult]
- func ToScanResult(totalBytes int64, totalItems int, scannedPaths []string, ...) domain.ScanResult
- func ToScanResultFromError(err error) result.Result[domain.ScanResult]
- func ToTimedCleanResult(bytesResult result.Result[int64], strategy domain.CleanStrategyType, ...) result.Result[domain.CleanResult]
- func ValidateAndConvertCleanResult(cleanResult domain.CleanResult) result.Result[domain.CleanResult]
- func ValidateAndConvertScanResult(scanResult domain.ScanResult) result.Result[domain.ScanResult]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CombineCleanResults ¶
func CombineCleanResults(results []domain.CleanResult) domain.CleanResult
CombineCleanResults combines multiple CleanResults into one.
func ExtractBytesFromCleanResult ¶
func ExtractBytesFromCleanResult( cleanResult result.Result[domain.CleanResult], ) result.Result[int64]
ExtractBytesFromCleanResult extracts int64 from domain.CleanResult (for adapter compatibility).
func NewCleanResult ¶
func NewCleanResult( strategy domain.CleanStrategyType, itemsRemoved int, freedBytes int64, ) domain.CleanResult
NewCleanResult creates a valid CleanResult with basic strategy and metrics.
Parameters:
- strategy: The cleaning strategy used (e.g., StrategyAggressive, StrategyDryRun)
- itemsRemoved: Number of items successfully removed
- freedBytes: Total bytes freed by the operation
Returns:
- domain.CleanResult: A fully initialized CleanResult with current timestamp
Example:
result := NewCleanResult(domain.CleanStrategyType(domain.StrategyAggressiveType), 5, 1024*1024*100)
fmt.Printf("Freed %d bytes", result.FreedBytes)
func NewCleanResultWithFailures ¶
func NewCleanResultWithFailures( strategy domain.CleanStrategyType, itemsRemoved, itemsFailed int, freedBytes int64, cleanTime time.Duration, ) domain.CleanResult
NewCleanResultWithFailures creates a CleanResult with failure tracking for detailed reporting.
Use this function when some operations failed and you need to track both successful and failed operations separately. This is useful for complex multi-step cleaning operations.
Parameters:
- strategy: The cleaning strategy used
- itemsRemoved: Number of items successfully removed
- itemsFailed: Number of items that failed to remove
- freedBytes: Total bytes freed by successful operations
- cleanTime: Time duration of the cleaning operation
Returns:
- domain.CleanResult: A fully initialized CleanResult with failure tracking
Example:
result := NewCleanResultWithFailures(domain.CleanStrategyType(domain.StrategyConservativeType),
5, 2, 1024*1024*100, time.Second*30)
fmt.Printf("Success: %d, Failed: %d", result.ItemsRemoved, result.ItemsFailed)
func NewCleanResultWithSizeEstimate ¶
func NewCleanResultWithSizeEstimate( strategy domain.CleanStrategyType, itemsRemoved int, freedBytes int64, sizeEstimate domain.SizeEstimate, ) domain.CleanResult
NewCleanResultWithSizeEstimate creates a CleanResult with size estimate for dry-run reporting.
Use this function when you need to include size estimate information, typically for dry-run operations where you want to show the user what would be cleaned.
Parameters:
- strategy: The cleaning strategy used
- itemsRemoved: Number of items that would be removed
- freedBytes: Total bytes that would be freed
- sizeEstimate: Size estimate with known bytes and status
Returns:
- domain.CleanResult: A fully initialized CleanResult with size estimate
Example:
estimate := domain.SizeEstimate{Known: 1024*1024*100, Status: domain.SizeEstimateStatusKnown}
result := NewCleanResultWithSizeEstimate(domain.CleanStrategyType(domain.StrategyDryRunType),
5, 1024*1024*100, estimate)
func NewCleanResultWithTiming ¶
func NewCleanResultWithTiming( strategy domain.CleanStrategyType, itemsRemoved int, freedBytes int64, cleanTime time.Duration, ) domain.CleanResult
NewCleanResultWithTiming creates a CleanResult with custom timing information.
Use this function when you have precise timing measurements for the operation. This provides more accurate metrics than the basic NewCleanResult function.
Parameters:
- strategy: The cleaning strategy used
- itemsRemoved: Number of items successfully removed
- freedBytes: Total bytes freed by the operation
- cleanTime: Time duration of the cleaning operation
Returns:
- domain.CleanResult: A fully initialized CleanResult with timing data
Example:
startTime := time.Now() // ... perform cleaning ... cleanTime := time.Since(startTime) result := NewCleanResultWithTiming(domain.CleanStrategyType(domain.StrategyAggressiveType), 5, 1024*1024*100, cleanTime)
func NewCleanResultWithTimingAndSize ¶
func NewCleanResultWithTimingAndSize( strategy domain.CleanStrategyType, itemsRemoved, itemsFailed int, freedBytes int64, cleanTime time.Duration, sizeEstimate domain.SizeEstimate, ) domain.CleanResult
NewCleanResultWithTimingAndSize creates a CleanResult with timing and size estimate.
Use this function when you need both precise timing and size estimate information. This is useful for real cleaning operations where you tracked time and know the exact bytes freed.
Parameters:
- strategy: The cleaning strategy used
- itemsRemoved: Number of items successfully removed
- itemsFailed: Number of items that failed to remove
- freedBytes: Total bytes freed by the operation
- cleanTime: Time duration of the cleaning operation
- sizeEstimate: Size estimate with known bytes and status
Returns:
- domain.CleanResult: A fully initialized CleanResult with timing and size estimate
func NewScanResult ¶
func NewScanResult( totalBytes int64, totalItems int, scannedPaths []string, scanDuration time.Duration, ) domain.ScanResult
NewScanResult creates a valid ScanResult with all required metrics and metadata.
This is the central function for creating scan results throughout the application. All scanning operations should use this function to ensure consistent data.
Parameters:
- totalBytes: Total bytes found during scanning
- totalItems: Total number of items discovered
- scannedPaths: List of paths that were scanned
- scanDuration: Time taken to perform the scan
Returns:
- domain.ScanResult: A fully initialized ScanResult with current timestamp
Example:
paths := []string{"/nix/store", "/tmp"}
result := NewScanResult(1024*1024*500, 1000, paths, time.Second*10)
fmt.Printf("Scanned %d items in %v", result.TotalItems, result.ScanTime)
func ToCleanResult ¶
ToCleanResult converts primitive Result[int64] to domain Result[domain.CleanResult] with conservative strategy.
This is the simplest conversion function that automatically uses conservative strategy. Use this when you don't need custom strategy information.
Parameters:
- bytesResult: Result[int64] containing bytes freed from primitive operation
Returns:
- result.Result[domain.CleanResult]: Converted result with conservative strategy
Example:
bytesResult := adapter.GetStoreSize(ctx)
cleanResult := ToCleanResult(bytesResult)
if cleanResult.IsOk() {
fmt.Printf("Freed %d bytes", cleanResult.Value().FreedBytes)
}
func ToCleanResultFromError ¶
func ToCleanResultFromError(err error) result.Result[domain.CleanResult]
ToCleanResultFromError converts error to Result[domain.CleanResult].
func ToCleanResultFromItems ¶
func ToCleanResultFromItems( itemsRemoved int, bytesResult result.Result[int64], strategy domain.CleanStrategyType, ) result.Result[domain.CleanResult]
ToCleanResultFromItems converts items count and bytes to domain Result[domain.CleanResult].
Use this function when you have both the number of items removed and the bytes freed. This provides more detailed metrics than just bytes conversion alone.
Parameters:
- itemsRemoved: Number of items successfully removed
- bytesResult: Result[int64] containing bytes freed from operation
- strategy: CleanStrategy enum value for the cleaning strategy
Returns:
- result.Result[domain.CleanResult]: Converted result with items and bytes data
Example:
bytesResult := adapter.CollectGarbage(ctx)
cleanResult := ToCleanResultFromItems(5, bytesResult,
domain.CleanStrategyType(domain.StrategyAggressiveType))
if cleanResult.IsOk() {
fmt.Printf("Removed %d items, freed %d bytes",
cleanResult.Value().ItemsRemoved, cleanResult.Value().FreedBytes)
}
func ToCleanResultWithStrategy ¶
func ToCleanResultWithStrategy( bytesResult result.Result[int64], strategy domain.CleanStrategyType, ) result.Result[domain.CleanResult]
ToCleanResultWithStrategy converts primitive Result[int64] to domain.Result[domain.CleanResult] with custom strategy.
Use this function when you need to specify the cleaning strategy used. This provides more detailed tracking of which operation type was performed.
Parameters:
- bytesResult: Result[int64] containing bytes freed from primitive operation
- strategy: CleanStrategy enum value (e.g., StrategyAggressive, StrategyConservative, StrategyDryRun)
Returns:
- result.Result[domain.CleanResult]: Converted result with specified strategy
Example:
bytesResult := adapter.CollectGarbage(ctx) cleanResult := ToCleanResultWithStrategy(bytesResult, domain.CleanStrategyType(domain.StrategyAggressiveType))
func ToScanResult ¶
func ToScanResult( totalBytes int64, totalItems int, scannedPaths []string, scanDuration time.Duration, ) domain.ScanResult
ToScanResult converts primitive scanning results to domain.ScanResult.
func ToScanResultFromError ¶
func ToScanResultFromError(err error) result.Result[domain.ScanResult]
ToScanResultFromError converts error to Result[domain.ScanResult].
func ToTimedCleanResult ¶
func ToTimedCleanResult( bytesResult result.Result[int64], strategy domain.CleanStrategyType, cleanTime time.Duration, ) result.Result[domain.CleanResult]
ToTimedCleanResult creates a timed CleanResult from bytes and duration.
func ValidateAndConvertCleanResult ¶
func ValidateAndConvertCleanResult( cleanResult domain.CleanResult, ) result.Result[domain.CleanResult]
ValidateAndConvertCleanResult ensures CleanResult is valid before returning.
func ValidateAndConvertScanResult ¶
func ValidateAndConvertScanResult(scanResult domain.ScanResult) result.Result[domain.ScanResult]
ValidateAndConvertScanResult ensures ScanResult is valid before returning.
Types ¶
This section is empty.