ax(mining): remove banned fmt import from version.go
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Replace fmt.Errorf with ErrInternal().WithCause() and
fmt.Sprintf URL with string concatenation + strconv.Itoa.

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 16:02:08 +01:00
parent 1edbd19f25
commit b41084eafe
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -2,9 +2,9 @@ package mining
import (
"encoding/json"
"fmt"
"io"
"net/http"
"strconv"
)
var (
@ -50,14 +50,14 @@ func FetchLatestGitHubVersion(owner, repo string) (string, error) {
return tagName, nil
}
}
return "", fmt.Errorf("github API unavailable (circuit breaker open): %w", err)
return "", ErrInternal("github API unavailable (circuit breaker open)").WithCause(err)
}
return "", err
}
tagName, ok := result.(string)
if !ok {
return "", fmt.Errorf("unexpected result type from circuit breaker")
return "", ErrInternal("unexpected result type from circuit breaker")
}
return tagName, nil
@ -65,22 +65,22 @@ func FetchLatestGitHubVersion(owner, repo string) (string, error) {
// tag, err := fetchGitHubVersionDirect("xmrig", "xmrig") // "v6.21.0"; called via circuit breaker
func fetchGitHubVersionDirect(owner, repo string) (string, error) {
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/latest", owner, repo)
url := "https://api.github.com/repos/" + owner + "/" + repo + "/releases/latest"
resp, err := getHTTPClient().Get(url)
if err != nil {
return "", fmt.Errorf("failed to fetch version: %w", err)
return "", ErrInternal("failed to fetch version").WithCause(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
io.Copy(io.Discard, resp.Body) // Drain body to allow connection reuse
return "", fmt.Errorf("failed to get latest release: unexpected status code %d", resp.StatusCode)
return "", ErrInternal("failed to get latest release: unexpected status code " + strconv.Itoa(resp.StatusCode))
}
var release GitHubRelease
if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
return "", fmt.Errorf("failed to decode release: %w", err)
return "", ErrInternal("failed to decode release").WithCause(err)
}
return release.TagName, nil