github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/modfetch/repo.go (about)

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package modfetch
     6  
     7  import (
     8  	"github.com/shogo82148/std/context"
     9  	"github.com/shogo82148/std/io"
    10  	"github.com/shogo82148/std/time"
    11  
    12  	"github.com/shogo82148/std/cmd/go/internal/modfetch/codehost"
    13  )
    14  
    15  // A Repo represents a repository storing all versions of a single module.
    16  // It must be safe for simultaneous use by multiple goroutines.
    17  type Repo interface {
    18  	ModulePath() string
    19  
    20  	CheckReuse(ctx context.Context, old *codehost.Origin) error
    21  
    22  	Versions(ctx context.Context, prefix string) (*Versions, error)
    23  
    24  	Stat(ctx context.Context, rev string) (*RevInfo, error)
    25  
    26  	Latest(ctx context.Context) (*RevInfo, error)
    27  
    28  	GoMod(ctx context.Context, version string) (data []byte, err error)
    29  
    30  	Zip(ctx context.Context, dst io.Writer, version string) error
    31  }
    32  
    33  // A Versions describes the available versions in a module repository.
    34  type Versions struct {
    35  	Origin *codehost.Origin `json:",omitempty"`
    36  
    37  	List []string
    38  }
    39  
    40  // A RevInfo describes a single revision in a module repository.
    41  type RevInfo struct {
    42  	Version string
    43  	Time    time.Time
    44  
    45  	// These fields are used for Stat of arbitrary rev,
    46  	// but they are not recorded when talking about module versions.
    47  	Name  string `json:"-"`
    48  	Short string `json:"-"`
    49  
    50  	Origin *codehost.Origin `json:",omitempty"`
    51  }
    52  
    53  // Lookup returns the module with the given module path,
    54  // fetched through the given proxy.
    55  //
    56  // The distinguished proxy "direct" indicates that the path should be fetched
    57  // from its origin, and "noproxy" indicates that the patch should be fetched
    58  // directly only if GONOPROXY matches the given path.
    59  //
    60  // For the distinguished proxy "off", Lookup always returns a Repo that returns
    61  // a non-nil error for every method call.
    62  //
    63  // A successful return does not guarantee that the module
    64  // has any defined versions.
    65  func Lookup(ctx context.Context, proxy, path string) Repo