go-update/http_client.go
Claude 644986b8bb
chore(ax): Pass 1 AX compliance sweep — banned imports, test naming, comment style
- Remove fmt from updater.go, service.go, http_client.go, cmd.go, github.go, generic_http.go; replace with string concat, coreerr.E, cli.Print
- Remove strings from updater.go (inline byte comparisons) and service.go (inline helpers)
- Replace fmt.Sprintf in error paths with string concatenation throughout
- Add cli.Print for all stdout output in updater.go (CheckForUpdates, CheckOnly, etc.)
- Fix service_examples_test.go: restore original CheckForUpdates instead of setting nil
- Test naming: all test files now follow TestFile_Function_{Good,Bad,Ugly} with all three variants mandatory
- Comments: replace prose descriptions with usage-example style on all exported functions
- Remaining banned: strings/encoding/json in github.go and generic_http.go (no Core replacement in direct deps); os/os.exec in platform files (syscall-level, unavoidable without go-process)

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-31 08:42:13 +01:00

31 lines
627 B
Go

package updater
import (
"context"
"net/http"
"time"
)
const defaultHTTPTimeout = 30 * time.Second
var NewHTTPClient = func() *http.Client {
return &http.Client{Timeout: defaultHTTPTimeout}
}
func newAgentRequest(ctx context.Context, method, url string) (*http.Request, error) {
req, err := http.NewRequestWithContext(ctx, method, url, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", updaterUserAgent())
return req, nil
}
func updaterUserAgent() string {
version := formatVersionForDisplay(Version, true)
if version == "" {
version = "unknown"
}
return "agent-go-update/" + version
}