fix(indexers): PTP API test function (#1771)

* fix(indexer): ptp api test

* fix: wrong type

* Revert "fix: wrong type"

This reverts commit 282d7c0c007b41b7323c58b3b450ffbf98c56917.
This commit is contained in:
soup 2024-10-19 14:43:11 +02:00 committed by GitHub
parent f7e635d5ae
commit 636129f282
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 7 deletions

View file

@ -104,6 +104,33 @@ type Torrent struct {
RemasterYear *string `json:"RemasterYear,omitempty"`
}
// custom unmarshal method for Torrent
func (t *Torrent) UnmarshalJSON(data []byte) error {
type Alias Torrent
aux := &struct {
Id interface{} `json:"Id"`
*Alias
}{
Alias: (*Alias)(t),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
switch id := aux.Id.(type) {
case float64:
t.Id = fmt.Sprintf("%.0f", id)
case string:
t.Id = id
default:
return fmt.Errorf("unexpected type for Id: %T", aux.Id)
}
return nil
}
func (c *Client) Do(req *http.Request) (*http.Response, error) {
ctx := context.Background()
err := c.rateLimiter.Wait(ctx) // This is a blocking call. Honors the rate limit