From a706b00c10a9e4054169488872784f23b1709ca1 Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Tue, 23 Sep 2014 21:19:56 -0600 Subject: [PATCH 1/4] use gopkg.in/check.v1 --- version_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/version_test.go b/version_test.go index 887068d..255ceee 100644 --- a/version_test.go +++ b/version_test.go @@ -1,8 +1,9 @@ package main import ( - . "launchpad.net/gocheck" "testing" + + . "gopkg.in/check.v1" ) func Test(t *testing.T) { TestingT(t) } From 06fff2f2c85d55811098c2e17a68e0091b303abd Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Tue, 23 Sep 2014 22:22:44 -0600 Subject: [PATCH 2/4] add a few comments --- main.go | 14 ++++++-------- version.go | 6 ++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index df72f05..a5a642c 100644 --- a/main.go +++ b/main.go @@ -29,9 +29,6 @@ func main() { func run() error { flag.Parse() - //if len(flag.Args()) > 0 { - // return fmt.Errorf("too many arguments: %s", flag.Args()[0]) - //} http.HandleFunc("/", handler) @@ -68,11 +65,12 @@ go get {{.GopkgPath}} `)) +// Repo represents a source code repository on GitHub. type Repo struct { User string Name string SubPath string - OldFormat bool + OldFormat bool // The old /v2/pkg format. MajorVersion Version AllVersions VersionList } @@ -91,12 +89,12 @@ func (repo *Repo) GopkgRoot() string { 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 { 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. func (repo *Repo) GopkgVersionRoot(version Version) string { version.Minor = -1 @@ -222,8 +220,8 @@ var httpClient = &http.Client{Timeout: 10 * time.Second} const refsSuffix = ".git/info/refs?service=git-upload-pack" -var ErrNoRepo = errors.New("repository not found in github") -var ErrNoVersion = errors.New("version reference not found in github") +var ErrNoRepo = errors.New("repository not found in GitHub") +var ErrNoVersion = errors.New("version reference not found in GitHub") func hackedRefs(repo *Repo) (data []byte, versions []Version, err error) { resp, err := httpClient.Get("https://" + repo.GitHubRoot() + refsSuffix) diff --git a/version.go b/version.go index f16f7fe..f0e0718 100644 --- a/version.go +++ b/version.go @@ -4,6 +4,8 @@ import ( "fmt" ) +// Version is a semantic version number (SemVer). +// An element that is not present is represented as -1. type Version struct { 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) } +// Less returns true if v is less than other. func (v Version) Less(other Version) bool { if 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 } +// Contains returns true if other >= v yet below the next major version. func (v Version) Contains(other Version) bool { if v.Patch != -1 { return v == other @@ -41,10 +45,12 @@ func (v Version) Contains(other Version) bool { return v.Major == other.Major } +// IsValid tests if a version is valid. func (v Version) IsValid() bool { return v != InvalidVersion } +// InvalidVersion represents a version that can't be parsed. var InvalidVersion = Version{-1, -1, -1} func parseVersion(s string) (Version, bool) { From b1f2f8e0fd683db61158f271e2acccec309ed041 Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Tue, 23 Sep 2014 22:24:57 -0600 Subject: [PATCH 3/4] minimal README --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..1189193 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# gopkg.in Stable APIs for the Go language + +See [http://labix.org/gopkg.in](http://labix.org/gopkg.in). From 2ed03dbf05645cc449d674802dc906389552b53c Mon Sep 17 00:00:00 2001 From: Nathan Youngman Date: Wed, 24 Sep 2014 17:44:47 -0600 Subject: [PATCH 4/4] revisions based on @niemeyer's review --- README.md | 2 +- version.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1189193..bcec69b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # gopkg.in Stable APIs for the Go language -See [http://labix.org/gopkg.in](http://labix.org/gopkg.in). +See [http://gopkg.in](http://gopkg.in). diff --git a/version.go b/version.go index f0e0718..d99cf46 100644 --- a/version.go +++ b/version.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// Version is a semantic version number (SemVer). +// Version represents a version number. // An element that is not present is represented as -1. type Version struct { Major, Minor, Patch int @@ -23,7 +23,7 @@ func (v Version) String() string { return fmt.Sprintf("v%d.%d.%d", v.Major, v.Minor, v.Patch) } -// Less returns true if v is less than other. +// Less returns whether v is less than other. func (v Version) Less(other Version) bool { if v.Major != other.Major { return v.Major < other.Major @@ -34,7 +34,12 @@ func (v Version) Less(other Version) bool { return v.Patch < other.Patch } -// Contains returns true if other >= v yet below the next major version. +// Contains returns whether version v contains version other. +// Version v is defined to contain version other when they both have the same Major +// version and v.Minor and v.Patch are either undefined or are equal to other's. +// +// For example, Version{1, 1, -1} contains both Version{1, 1, -1} and Version{1, 1, 2}, +// but not Version{1, -1, -1} or Version{1, 2, -1}. func (v Version) Contains(other Version) bool { if v.Patch != -1 { return v == other @@ -45,7 +50,6 @@ func (v Version) Contains(other Version) bool { return v.Major == other.Major } -// IsValid tests if a version is valid. func (v Version) IsValid() bool { return v != InvalidVersion }