add a few comments
This commit is contained in:
parent
a706b00c10
commit
06fff2f2c8
14
main.go
14
main.go
@ -29,9 +29,6 @@ func main() {
|
|||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
//if len(flag.Args()) > 0 {
|
|
||||||
// return fmt.Errorf("too many arguments: %s", flag.Args()[0])
|
|
||||||
//}
|
|
||||||
|
|
||||||
http.HandleFunc("/", handler)
|
http.HandleFunc("/", handler)
|
||||||
|
|
||||||
@ -68,11 +65,12 @@ go get {{.GopkgPath}}
|
|||||||
</html>
|
</html>
|
||||||
`))
|
`))
|
||||||
|
|
||||||
|
// Repo represents a source code repository on GitHub.
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
User string
|
User string
|
||||||
Name string
|
Name string
|
||||||
SubPath string
|
SubPath string
|
||||||
OldFormat bool
|
OldFormat bool // The old /v2/pkg format.
|
||||||
MajorVersion Version
|
MajorVersion Version
|
||||||
AllVersions VersionList
|
AllVersions VersionList
|
||||||
}
|
}
|
||||||
@ -91,12 +89,12 @@ func (repo *Repo) GopkgRoot() string {
|
|||||||
return repo.GopkgVersionRoot(repo.MajorVersion)
|
return repo.GopkgVersionRoot(repo.MajorVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GopkgRoot returns the package path at gopkg.in, without a schema.
|
// GopkgPath returns the package path at gopkg.in, without a schema.
|
||||||
func (repo *Repo) GopkgPath() string {
|
func (repo *Repo) GopkgPath() string {
|
||||||
return repo.GopkgVersionRoot(repo.MajorVersion) + repo.SubPath
|
return repo.GopkgVersionRoot(repo.MajorVersion) + repo.SubPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// GopkgVerisonRoot returns the package root in gopkg.in for the
|
// GopkgVersionRoot returns the package root in gopkg.in for the
|
||||||
// provided version, without a schema.
|
// provided version, without a schema.
|
||||||
func (repo *Repo) GopkgVersionRoot(version Version) string {
|
func (repo *Repo) GopkgVersionRoot(version Version) string {
|
||||||
version.Minor = -1
|
version.Minor = -1
|
||||||
@ -222,8 +220,8 @@ var httpClient = &http.Client{Timeout: 10 * time.Second}
|
|||||||
|
|
||||||
const refsSuffix = ".git/info/refs?service=git-upload-pack"
|
const refsSuffix = ".git/info/refs?service=git-upload-pack"
|
||||||
|
|
||||||
var ErrNoRepo = errors.New("repository not found in github")
|
var ErrNoRepo = errors.New("repository not found in GitHub")
|
||||||
var ErrNoVersion = errors.New("version reference not found in github")
|
var ErrNoVersion = errors.New("version reference not found in GitHub")
|
||||||
|
|
||||||
func hackedRefs(repo *Repo) (data []byte, versions []Version, err error) {
|
func hackedRefs(repo *Repo) (data []byte, versions []Version, err error) {
|
||||||
resp, err := httpClient.Get("https://" + repo.GitHubRoot() + refsSuffix)
|
resp, err := httpClient.Get("https://" + repo.GitHubRoot() + refsSuffix)
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Version is a semantic version number (SemVer).
|
||||||
|
// An element that is not present is represented as -1.
|
||||||
type Version struct {
|
type Version struct {
|
||||||
Major, Minor, Patch int
|
Major, Minor, Patch int
|
||||||
}
|
}
|
||||||
@ -21,6 +23,7 @@ func (v Version) String() string {
|
|||||||
return fmt.Sprintf("v%d.%d.%d", v.Major, v.Minor, v.Patch)
|
return fmt.Sprintf("v%d.%d.%d", v.Major, v.Minor, v.Patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Less returns true if v is less than other.
|
||||||
func (v Version) Less(other Version) bool {
|
func (v Version) Less(other Version) bool {
|
||||||
if v.Major != other.Major {
|
if v.Major != other.Major {
|
||||||
return v.Major < other.Major
|
return v.Major < other.Major
|
||||||
@ -31,6 +34,7 @@ func (v Version) Less(other Version) bool {
|
|||||||
return v.Patch < other.Patch
|
return v.Patch < other.Patch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Contains returns true if other >= v yet below the next major version.
|
||||||
func (v Version) Contains(other Version) bool {
|
func (v Version) Contains(other Version) bool {
|
||||||
if v.Patch != -1 {
|
if v.Patch != -1 {
|
||||||
return v == other
|
return v == other
|
||||||
@ -41,10 +45,12 @@ func (v Version) Contains(other Version) bool {
|
|||||||
return v.Major == other.Major
|
return v.Major == other.Major
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsValid tests if a version is valid.
|
||||||
func (v Version) IsValid() bool {
|
func (v Version) IsValid() bool {
|
||||||
return v != InvalidVersion
|
return v != InvalidVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InvalidVersion represents a version that can't be parsed.
|
||||||
var InvalidVersion = Version{-1, -1, -1}
|
var InvalidVersion = Version{-1, -1, -1}
|
||||||
|
|
||||||
func parseVersion(s string) (Version, bool) {
|
func parseVersion(s string) (Version, bool) {
|
||||||
|
Loading…
Reference in New Issue
Block a user