7b7df2c6af
This PR starts to implement the refactoring described at https://github.com/ooni/probe/issues/1951. I originally wrote more patches than the ones in this PR, but overall they were not readable. Since I want to squash and merge, here's a reasonable subset of the original patches that will still be readable and understandable in the future.
30 lines
685 B
Go
30 lines
685 B
Go
package probeservices
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/httpx"
|
|
)
|
|
|
|
type checkReportIDResponse struct {
|
|
Found bool `json:"found"`
|
|
}
|
|
|
|
// CheckReportID checks whether the given ReportID exists.
|
|
func (c Client) CheckReportID(ctx context.Context, reportID string) (bool, error) {
|
|
query := url.Values{}
|
|
query.Add("report_id", reportID)
|
|
var response checkReportIDResponse
|
|
err := (&httpx.APIClient{
|
|
BaseURL: c.BaseURL,
|
|
HTTPClient: c.HTTPClient,
|
|
Logger: c.Logger,
|
|
UserAgent: c.UserAgent,
|
|
}).GetJSONWithQuery(ctx, "/api/_/check_report_id", query, &response)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return response.Found, nil
|
|
}
|