diff --git a/find/client/client.go b/find/client/client.go index 6d4fe08..4fe5e80 100644 --- a/find/client/client.go +++ b/find/client/client.go @@ -55,8 +55,8 @@ func New(baseURL string, options ...Option) (*Client, error) { }, nil } -// Find looks up content entries by multihash. If no results are found then a -// nil response without error is returned. +// Find looks up content entries by multihash. If no results are found then an +// empty response without error is returned. func (c *Client) Find(ctx context.Context, m multihash.Multihash) (*model.FindResponse, error) { u := c.findURL.JoinPath(m.B58String()) req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil) @@ -72,7 +72,7 @@ func (c *Client) Find(ctx context.Context, m multihash.Multihash) (*model.FindRe // Handle failed requests if resp.StatusCode != http.StatusOK { if resp.StatusCode == http.StatusNotFound { - return nil, nil + return &model.FindResponse{}, nil } return nil, fmt.Errorf("find query failed: %v", http.StatusText(resp.StatusCode)) } diff --git a/find/client/dhash_client.go b/find/client/dhash_client.go index a346a62..02fa398 100644 --- a/find/client/dhash_client.go +++ b/find/client/dhash_client.go @@ -99,7 +99,7 @@ func (c *DHashClient) PCache() *pcache.ProviderCache { // Find launches FindAsync in a separate go routine and assembles the result // into FindResponse as if it was a synchronous invocation. If no results are -// found then a nil response without error is returned. +// found then an empty response without error is returned. func (c *DHashClient) Find(ctx context.Context, mh multihash.Multihash) (*model.FindResponse, error) { resChan := make(chan model.ProviderResult) errChan := make(chan error, 1) @@ -117,7 +117,7 @@ func (c *DHashClient) Find(ctx context.Context, mh multihash.Multihash) (*model. return nil, err } if len(providerResults) == 0 { - return nil, nil + return &model.FindResponse{}, nil } return &model.FindResponse{ diff --git a/find/client/interface.go b/find/client/interface.go index 99c7c8f..f237423 100644 --- a/find/client/interface.go +++ b/find/client/interface.go @@ -13,13 +13,13 @@ import ( // Finder is the interface implemented by all find clients. type Finder interface { // Find queries for provider content records for a single multihash. If no - // results are found then a nil response without error is returned. + // results are found then an empty response without error is returned. Find(context.Context, multihash.Multihash) (*model.FindResponse, error) } // FindBatch is a convenience function to lookup results for multiple // multihashes. This works with either the Client or DHashClient. If no results -// are found then a nil response without error is returned. +// are found then an empty response without error is returned. func FindBatch(ctx context.Context, finder Finder, mhs []multihash.Multihash) (*model.FindResponse, error) { var resp *model.FindResponse for i := range mhs { @@ -41,5 +41,8 @@ func FindBatch(ctx context.Context, finder Finder, mhs []multihash.Multihash) (* resp.MultihashResults = append(resp.MultihashResults, r.MultihashResults...) } } + if resp == nil { + resp = &model.FindResponse{} + } return resp, nil }