Skip to content
Permalink
Browse files

version: add Go version to VersionHandler

  • Loading branch information
narqo committed Mar 3, 2020
1 parent ec839ec commit 7e7096f491e6c2a170eddcc02ed6f2a1b213a7b6
Showing with 30 additions and 24 deletions.
  1. +3 −3 Makefile
  2. +1 −1 cmd/profefe/main.go
  3. +2 −12 pkg/profefe/version_handler.go
  4. +24 −8 version/version.go
@@ -13,9 +13,9 @@ ifndef VERSION
VERSION := git-$(GITSHA)
endif

LDFLAGS += -X $(PKG)/version.Version=$(VERSION)
LDFLAGS += -X $(PKG)/version.Commit=$(GITSHA)
LDFLAGS += -X $(PKG)/version.BuildTime=$(BUILDTIME)
LDFLAGS += -X $(PKG)/version.version=$(VERSION)
LDFLAGS += -X $(PKG)/version.commit=$(GITSHA)
LDFLAGS += -X $(PKG)/version.buildTime=$(BUILDTIME)

BINDIR := $(CURDIR)/bin
BUILDDIR := $(CURDIR)/BUILD
@@ -40,7 +40,7 @@ func main() {
flag.Parse()

if *printVersion {
fmt.Println(version.String())
fmt.Println(version.Details())
os.Exit(1)
}

@@ -6,16 +6,6 @@ import (
"github.com/profefe/profefe/version"
)

func VersionHandler(w http.ResponseWriter, r *http.Request) {
resp := struct {
Version string `json:"version"`
Commit string `json:"commit"`
BuildTime string `json:"build_time"`
}{
Version: version.Version,
Commit: version.Commit,
BuildTime: version.BuildTime,
}

ReplyJSON(w, resp)
func VersionHandler(w http.ResponseWriter, _ *http.Request) {
ReplyJSON(w, version.Details())
}
@@ -6,18 +6,34 @@ import (
)

var (
Version string
Commit string
BuildTime string
version string
commit string
buildTime string
)

type Version struct {
Version string `json:"version"`
Commit string `json:"commit"`
BuildTime string `json:"build_time"`
GoVersion string `json:"go_version"`
}

func Details() Version {
return Version{
Version: version,
Commit: commit,
BuildTime: buildTime,
GoVersion: runtime.Version(),
}
}

// String returns version details as pretty printed string.
func String() string {
func (v Version) String() string {
return fmt.Sprintf(
"profefe version %s, commit %s (%s), go version %s",
Version,
Commit,
BuildTime,
runtime.Version(),
v.Version,
v.Commit,
v.BuildTime,
v.GoVersion,
)
}

0 comments on commit 7e7096f

Please sign in to comment.
You can’t perform that action at this time.