include build time in binary

This commit is contained in:
Alex Grintsvayg 2018-08-30 14:41:50 -04:00
parent 473e7e3b07
commit 22f42d5559
3 changed files with 21 additions and 4 deletions

View file

@ -5,7 +5,7 @@ VENDOR_DIR = vendor
IMPORT_PATH = github.com/lbryio/reflector.go
VERSION = $(shell git --git-dir=${DIR}/.git describe --dirty --always --long --abbrev=7)
LDFLAGS = -ldflags "-X ${IMPORT_PATH}/meta.Version=${VERSION}"
LDFLAGS = -ldflags "-X ${IMPORT_PATH}/meta.Version=${VERSION} -X ${IMPORT_PATH}/meta.Time=$(shell date +%s)"
.PHONY: build dep clean test

View file

@ -1,10 +1,10 @@
package cmd
import (
"log"
"fmt"
"time"
"github.com/lbryio/reflector.go/meta"
"github.com/spf13/cobra"
)
@ -18,5 +18,5 @@ func init() {
}
func versionCmd(cmd *cobra.Command, args []string) {
log.Printf("version %s\n", meta.Version)
fmt.Printf("version %s (%s)\n", meta.Version, meta.BuildTime.Format(time.RFC3339))
}

View file

@ -1,3 +1,20 @@
package meta
import (
"strconv"
"time"
)
var Version = ""
var Time = ""
var BuildTime time.Time
func init() {
if Time != "" {
t, err := strconv.Atoi(Time)
if err != nil {
return
}
BuildTime = time.Unix(int64(t), 0).UTC()
}
}