Copyright 2019 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Package index provides a client for communicating with the module index.
package index

import (
	
	
	
	
	
	
	
	

	
	
	
	
)
A Client is used by the worker service to communicate with the module index.
URL of the module index
client used for HTTP requests. It is mutable for testing purposes.
New constructs a *Client using the provided rawurl, which is expected to be an absolute URI that can be directly passed to http.Get.
func ( string) ( *Client,  error) {
	defer derrors.Add(&, "index.New(%q)", )

	,  := url.Parse()
	if  != nil {
		return nil, fmt.Errorf("url.Parse(%q): %v", , )
	}
	if .Scheme != "https" {
		return nil, fmt.Errorf("scheme must be https (got %s)", .Scheme)
	}
	return &Client{url: strings.TrimRight(, "/"), httpClient: &http.Client{Transport: &ochttp.Transport{}}}, nil
}

func ( *Client) ( time.Time,  int) string {
	 := url.Values{}
	.Set("since", .Format(time.RFC3339))
	if  > 0 {
		.Set("limit", strconv.Itoa())
	}
	return fmt.Sprintf("%s?%s", .url, .Encode())
}
GetVersions queries the index for new versions.
func ( *Client) ( context.Context,  time.Time,  int) ( []*internal.IndexVersion,  error) {
	defer derrors.Wrap(&, "index.Client.GetVersions(ctx, %s, %d)", , )

	 := .pollURL(, )
	,  := ctxhttp.Get(, .httpClient, )
	if  != nil {
		return nil, fmt.Errorf("ctxhttp.Get(ctx, nil, %q): %v", , )
	}
	defer .Body.Close()

	var  []*internal.IndexVersion
	 := json.NewDecoder(.Body)
The module index returns a stream of JSON objects formatted with newline as the delimiter.
	for .More() {
		var  internal.IndexVersion
		if  := .Decode(&);  != nil {
			return nil, fmt.Errorf("decoding JSON: %v", )
		}
		 = append(, &)
	}
	return , nil