Version is a package now, will be re-used across codebase.

master
Harshavardhana 9 years ago
parent 1c5454e007
commit 7093a05ab1
  1. 2
      Makefile
  2. 3
      main.go
  3. 4
      pkg/server/api/headers.go
  4. 2
      pkg/version/genversion.go
  5. 2
      pkg/version/version.go
  6. 37
      pkg/version/version_test.go
  7. 12
      verify-runtime.go
  8. 3
      version-main.go

@ -50,7 +50,7 @@ release: genversion
genversion: genversion:
@echo "Generating new minio version.go" @echo "Generating new minio version.go"
@go run genversion.go @cd ./pkg/version; go run genversion.go; cd - 1>/dev/null
pkg-remove: pkg-remove:
@GO15VENDOREXPERIMENT=1 govendor remove $(PKG) @GO15VENDOREXPERIMENT=1 govendor remove $(PKG)

@ -27,6 +27,7 @@ import (
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/minio/cli" "github.com/minio/cli"
"github.com/minio/minio/pkg/version"
) )
func init() { func init() {
@ -80,7 +81,7 @@ func init() {
// getFormattedVersion - // getFormattedVersion -
func getFormattedVersion() string { func getFormattedVersion() string {
t, _ := time.Parse(time.RFC3339Nano, Version) t, _ := time.Parse(time.RFC3339Nano, version.Version)
if t.IsZero() { if t.IsZero() {
return "" return ""
} }

@ -22,9 +22,11 @@ import (
"encoding/json" "encoding/json"
"encoding/xml" "encoding/xml"
"net/http" "net/http"
"runtime"
"strconv" "strconv"
"github.com/minio/minio/pkg/donut" "github.com/minio/minio/pkg/donut"
"github.com/minio/minio/pkg/version"
) )
// No encoder interface exists, so we create one. // No encoder interface exists, so we create one.
@ -51,7 +53,7 @@ func generateRequestID() []byte {
func setCommonHeaders(w http.ResponseWriter, acceptsType string, contentLength int) { func setCommonHeaders(w http.ResponseWriter, acceptsType string, contentLength int) {
// set unique request ID for each reply // set unique request ID for each reply
w.Header().Set("X-Amz-Request-Id", string(generateRequestID())) 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("Accept-Ranges", "bytes")
w.Header().Set("Content-Type", acceptsType) w.Header().Set("Content-Type", acceptsType)
w.Header().Set("Connection", "close") w.Header().Set("Connection", "close")

@ -35,7 +35,7 @@ func writeVersion(version Version) error {
var versionTemplate = `// -------- DO NOT EDIT -------- var versionTemplate = `// -------- DO NOT EDIT --------
// This file is autogenerated by genversion.go during the release process. // This file is autogenerated by genversion.go during the release process.
package main package version
// Version autogenerated // Version autogenerated
const Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}} const Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}}

@ -1,7 +1,7 @@
// -------- DO NOT EDIT -------- // -------- DO NOT EDIT --------
// This file is autogenerated by genversion.go during the release process. // This file is autogenerated by genversion.go during the release process.
package main package version
// Version autogenerated // Version autogenerated
const Version = "2015-08-14T03:23:47.250240049Z" const Version = "2015-08-14T03:23:47.250240049Z"

@ -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)
}

@ -44,12 +44,12 @@ func getNormalizedGolangVersion() string {
return version return version
} }
type version struct { type golangVersion struct {
major, minor, patch string major, minor, patch string
} }
func newVersion(v string) version { func newVersion(v string) golangVersion {
ver := version{} ver := golangVersion{}
verSlice := strings.Split(v, ".") verSlice := strings.Split(v, ".")
if len(verSlice) < 2 { if len(verSlice) < 2 {
Fatalln("Version string missing major and minor versions, cannot proceed exiting.") Fatalln("Version string missing major and minor versions, cannot proceed exiting.")
@ -67,11 +67,11 @@ func newVersion(v string) version {
return ver return ver
} }
func (v1 version) String() string { func (v1 golangVersion) String() string {
return fmt.Sprintf("%s%s%s", v1.major, v1.minor, v1.patch) 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()) ver, e := strconv.Atoi(v1.String())
if e != nil { if e != nil {
Fatalln("Unable to parse version string.") Fatalln("Unable to parse version string.")
@ -79,7 +79,7 @@ func (v1 version) Version() int {
return ver return ver
} }
func (v1 version) LessThan(v2 version) bool { func (v1 golangVersion) LessThan(v2 golangVersion) bool {
if v1.Version() < v2.Version() { if v1.Version() < v2.Version() {
return true return true
} }

@ -21,6 +21,7 @@ import (
"time" "time"
"github.com/minio/cli" "github.com/minio/cli"
"github.com/minio/minio/pkg/version"
) )
var versionCmd = cli.Command{ var versionCmd = cli.Command{
@ -39,7 +40,7 @@ EXAMPLES:
} }
func mainVersion(ctxx *cli.Context) { func mainVersion(ctxx *cli.Context) {
t, _ := time.Parse(time.RFC3339Nano, Version) t, _ := time.Parse(time.RFC3339Nano, version.Version)
if t.IsZero() { if t.IsZero() {
Println("") Println("")
return return

Loading…
Cancel
Save