refactor(downloader): store user agent on Client to avoid passing config twice #128

Closed
opened 2026-07-13 17:28:39 +00:00 by the.auditor · 1 comment
Owner

internal/downloader/client.go:38NewRequest requires cfg *config.Config even though the Client was already created from config in NewClient.

Suggestion: store userAgent string on the Client struct and use it in NewRequest instead of requiring cfg as a parameter. This simplifies the API and avoids passing config through unnecessarily.

type Client struct {
    http      *http.Client
    userAgent string
}

func NewClient(cfg *config.Config) *Client {
    return &Client{
        http:      ...,
        userAgent: cfg.UserAgent,
    }
}

func (c *Client) NewRequest(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", c.userAgent)
    return req, nil
}

Discovered during review of PR #127.

`internal/downloader/client.go:38` — `NewRequest` requires `cfg *config.Config` even though the `Client` was already created from config in `NewClient`. Suggestion: store `userAgent string` on the `Client` struct and use it in `NewRequest` instead of requiring `cfg` as a parameter. This simplifies the API and avoids passing config through unnecessarily. ```go type Client struct { http *http.Client userAgent string } func NewClient(cfg *config.Config) *Client { return &Client{ http: ..., userAgent: cfg.UserAgent, } } func (c *Client) NewRequest(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", c.userAgent) return req, nil } ``` Discovered during review of PR #127.
Owner

Closing — already implemented in PR #127. Client struct stores userAgent string, NewRequest uses it directly without requiring Config.

Closing — already implemented in PR #127. Client struct stores userAgent string, NewRequest uses it directly without requiring Config.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/pget#128
No description provided.