From 7093a05ab1311010d11ed41fbbb0de5570df5142 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 17 Sep 2015 20:06:28 -0700 Subject: [PATCH] Version is a package now, will be re-used across codebase. --- Makefile | 2 +- main.go | 3 +- pkg/server/api/headers.go | 4 ++- genversion.go => pkg/version/genversion.go | 2 +- version.go => pkg/version/version.go | 2 +- pkg/version/version_test.go | 37 ++++++++++++++++++++++ verify-runtime.go | 12 +++---- version-main.go | 3 +- 8 files changed, 53 insertions(+), 12 deletions(-) rename genversion.go => pkg/version/genversion.go (99%) rename version.go => pkg/version/version.go (92%) create mode 100644 pkg/version/version_test.go diff --git a/Makefile b/Makefile index 14ce032a1..9c4cd9885 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ release: genversion genversion: @echo "Generating new minio version.go" - @go run genversion.go + @cd ./pkg/version; go run genversion.go; cd - 1>/dev/null pkg-remove: @GO15VENDOREXPERIMENT=1 govendor remove $(PKG) diff --git a/main.go b/main.go index a1d91c93d..3d1bab8cf 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ import ( "github.com/dustin/go-humanize" "github.com/minio/cli" + "github.com/minio/minio/pkg/version" ) func init() { @@ -80,7 +81,7 @@ func init() { // getFormattedVersion - func getFormattedVersion() string { - t, _ := time.Parse(time.RFC3339Nano, Version) + t, _ := time.Parse(time.RFC3339Nano, version.Version) if t.IsZero() { return "" } diff --git a/pkg/server/api/headers.go b/pkg/server/api/headers.go index 8cda27472..a1997bf23 100644 --- a/pkg/server/api/headers.go +++ b/pkg/server/api/headers.go @@ -22,9 +22,11 @@ import ( "encoding/json" "encoding/xml" "net/http" + "runtime" "strconv" "github.com/minio/minio/pkg/donut" + "github.com/minio/minio/pkg/version" ) // No encoder interface exists, so we create one. @@ -51,7 +53,7 @@ func generateRequestID() []byte { func setCommonHeaders(w http.ResponseWriter, acceptsType string, contentLength int) { // set unique request ID for each reply w.Header().Set("X-Amz-Request-Id", string(generateRequestID())) - w.Header().Set("Server", "Minio") + w.Header().Set("Server", ("Minio/" + version.Version + " (" + runtime.GOOS + "," + runtime.GOARCH + ")")) w.Header().Set("Accept-Ranges", "bytes") w.Header().Set("Content-Type", acceptsType) w.Header().Set("Connection", "close") diff --git a/genversion.go b/pkg/version/genversion.go similarity index 99% rename from genversion.go rename to pkg/version/genversion.go index ec4e31255..dd2d12693 100644 --- a/genversion.go +++ b/pkg/version/genversion.go @@ -35,7 +35,7 @@ func writeVersion(version Version) error { var versionTemplate = `// -------- DO NOT EDIT -------- // This file is autogenerated by genversion.go during the release process. -package main +package version // Version autogenerated const Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}} diff --git a/version.go b/pkg/version/version.go similarity index 92% rename from version.go rename to pkg/version/version.go index 1d646b9f1..6424494e2 100644 --- a/version.go +++ b/pkg/version/version.go @@ -1,7 +1,7 @@ // -------- DO NOT EDIT -------- // This file is autogenerated by genversion.go during the release process. -package main +package version // Version autogenerated const Version = "2015-08-14T03:23:47.250240049Z" diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go new file mode 100644 index 000000000..0d92d7e67 --- /dev/null +++ b/pkg/version/version_test.go @@ -0,0 +1,37 @@ +/* + * Minio Cloud Storage, (C) 2015 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package version_test + +import ( + "testing" + "time" + + "github.com/minio/minio/pkg/version" + + . "gopkg.in/check.v1" +) + +func Test(t *testing.T) { TestingT(t) } + +type MySuite struct{} + +var _ = Suite(&MySuite{}) + +func (s *MySuite) TestVersion(c *C) { + _, err := time.Parse(version.Version, time.RFC3339Nano) + c.Assert(err, NotNil) +} diff --git a/verify-runtime.go b/verify-runtime.go index 6b40663a9..da1836c51 100644 --- a/verify-runtime.go +++ b/verify-runtime.go @@ -44,12 +44,12 @@ func getNormalizedGolangVersion() string { return version } -type version struct { +type golangVersion struct { major, minor, patch string } -func newVersion(v string) version { - ver := version{} +func newVersion(v string) golangVersion { + ver := golangVersion{} verSlice := strings.Split(v, ".") if len(verSlice) < 2 { Fatalln("Version string missing major and minor versions, cannot proceed exiting.") @@ -67,11 +67,11 @@ func newVersion(v string) version { return ver } -func (v1 version) String() string { +func (v1 golangVersion) String() string { return fmt.Sprintf("%s%s%s", v1.major, v1.minor, v1.patch) } -func (v1 version) Version() int { +func (v1 golangVersion) Version() int { ver, e := strconv.Atoi(v1.String()) if e != nil { Fatalln("Unable to parse version string.") @@ -79,7 +79,7 @@ func (v1 version) Version() int { return ver } -func (v1 version) LessThan(v2 version) bool { +func (v1 golangVersion) LessThan(v2 golangVersion) bool { if v1.Version() < v2.Version() { return true } diff --git a/version-main.go b/version-main.go index 8e26542a2..09b62bfdb 100644 --- a/version-main.go +++ b/version-main.go @@ -21,6 +21,7 @@ import ( "time" "github.com/minio/cli" + "github.com/minio/minio/pkg/version" ) var versionCmd = cli.Command{ @@ -39,7 +40,7 @@ EXAMPLES: } func mainVersion(ctxx *cli.Context) { - t, _ := time.Parse(time.RFC3339Nano, Version) + t, _ := time.Parse(time.RFC3339Nano, version.Version) if t.IsZero() { Println("") return