Rate Limiter: - Extract rate limiting to pkg/mining/ratelimiter.go with proper lifecycle - Add Stop() method to gracefully shutdown cleanup goroutine - Add RateLimiter.Middleware() for Gin integration - Add ClientCount() for monitoring - Fix goroutine leak in previous inline implementation Custom Errors: - Add pkg/mining/errors.go with MiningError type - Define error codes: MINER_NOT_FOUND, INSTALL_FAILED, TIMEOUT, etc. - Add predefined error constructors (ErrMinerNotFound, ErrStartFailed, etc.) - Support error chaining with WithCause, WithDetails, WithSuggestion - Include HTTP status codes and retry policies Service: - Add Service.Stop() method for graceful cleanup - Update CLI commands to use context.Background() for Manager methods Tests: - Add comprehensive tests for RateLimiter (token bucket, multi-IP, refill) - Add comprehensive tests for MiningError (codes, status, retryable) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// uninstallCmd represents the uninstall command
|
|
var uninstallCmd = &cobra.Command{
|
|
Use: "uninstall [miner_type]",
|
|
Short: "Uninstall a miner",
|
|
Long: `Stops the miner if it is running, removes all associated files, and updates the configuration.`,
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
minerType := args[0]
|
|
manager := getManager() // Assuming getManager() provides the singleton manager instance
|
|
|
|
fmt.Printf("Uninstalling %s...\n", minerType)
|
|
if err := manager.UninstallMiner(context.Background(), minerType); err != nil {
|
|
return fmt.Errorf("failed to uninstall miner: %w", err)
|
|
}
|
|
|
|
fmt.Printf("%s uninstalled successfully.\n", minerType)
|
|
|
|
// The doctor cache is implicitly updated by the manager's actions,
|
|
// but an explicit cache update can still be beneficial.
|
|
fmt.Println("Updating installation cache...")
|
|
if err := updateDoctorCache(); err != nil {
|
|
fmt.Printf("Warning: failed to update doctor cache: %v\n", err)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(uninstallCmd)
|
|
}
|