github.com/knieriem/gointernal@v0.2.0-pre2/cmd/go/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 "fmt" 9 "io" 10 "io/fs" 11 "time" 12 ) 13 14 const traceRepo = false // trace all repo actions, for debugging 15 16 // A Repo represents a repository storing all versions of a single module. 17 // It must be safe for simultaneous use by multiple goroutines. 18 type Repo interface { 19 // ModulePath returns the module path. 20 ModulePath() string 21 22 // Versions lists all known versions with the given prefix. 23 // Pseudo-versions are not included. 24 // 25 // Versions should be returned sorted in semver order 26 // (implementations can use semver.Sort). 27 // 28 // Versions returns a non-nil error only if there was a problem 29 // fetching the list of versions: it may return an empty list 30 // along with a nil error if the list of matching versions 31 // is known to be empty. 32 // 33 // If the underlying repository does not exist, 34 // Versions returns an error matching errors.Is(_, os.NotExist). 35 Versions(prefix string) ([]string, error) 36 37 // Stat returns information about the revision rev. 38 // A revision can be any identifier known to the underlying service: 39 // commit hash, branch, tag, and so on. 40 Stat(rev string) (*RevInfo, error) 41 42 // Latest returns the latest revision on the default branch, 43 // whatever that means in the underlying source code repository. 44 // It is only used when there are no tagged versions. 45 Latest() (*RevInfo, error) 46 47 // GoMod returns the go.mod file for the given version. 48 GoMod(version string) (data []byte, err error) 49 50 // Zip writes a zip file for the given version to dst. 51 Zip(dst io.Writer, version string) error 52 } 53 54 // A Rev describes a single revision in a module repository. 55 type RevInfo struct { 56 Version string // suggested version string for this revision 57 Time time.Time // commit time 58 59 // These fields are used for Stat of arbitrary rev, 60 // but they are not recorded when talking about module versions. 61 Name string `json:"-"` // complete ID in underlying repository 62 Short string `json:"-"` // shortened ID, for use in pseudo-version 63 } 64 65 // A notExistError is like fs.ErrNotExist, but with a custom message 66 type notExistError struct { 67 err error 68 } 69 70 func notExistErrorf(format string, args ...interface{}) error { 71 return notExistError{fmt.Errorf(format, args...)} 72 } 73 74 func (e notExistError) Error() string { 75 return e.err.Error() 76 } 77 78 func (notExistError) Is(target error) bool { 79 return target == fs.ErrNotExist 80 } 81 82 func (e notExistError) Unwrap() error { 83 return e.err 84 }