Skip to content

Commit

Permalink
add version
Browse files Browse the repository at this point in the history
  • Loading branch information
tonicmuroq committed Jul 26, 2016
1 parent cf3dd12 commit 5ddb711
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
REPO_PATH := gitlab.ricebook.net/platform/core
REVISION := $(shell git rev-parse HEAD || unknown)
GO_LDFLAGS ?= -s -X $(REPO_PATH)/version.REVISION=$(REVISION)

golang:
cd ./rpc/gen/; protoc --go_out=plugins=grpc:. core.proto

Expand All @@ -18,3 +22,6 @@ deps:
go get gopkg.in/libgit2/git2go.v23
go get golang.org/x/net/context
go get google.golang.org/grpc

build:
go build -ldflags "$(GO_LDFLAGS)" -a -tags netgo -installsuffix netgo -o eru-core
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"io/ioutil"
"net"
"net/http"
Expand All @@ -15,6 +16,7 @@ import (
"gitlab.ricebook.net/platform/core/rpc"
"gitlab.ricebook.net/platform/core/rpc/gen"
"gitlab.ricebook.net/platform/core/types"
"gitlab.ricebook.net/platform/core/version"
"google.golang.org/grpc"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -98,10 +100,14 @@ func serve() {
}

func main() {
cli.VersionPrinter = func(c *cli.Context) {
fmt.Print(version.VersionString())
}

app := cli.NewApp()
app.Name = "Eru-Core"
app.Name = version.NAME
app.Usage = "Run eru core"
app.Version = "2.0.0"
app.Version = version.VERSION
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config",
Expand Down
24 changes: 24 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package version

import (
"fmt"
"runtime"
"time"
)

var (
NAME = "Eru-Core"
VERSION = "1.0.0"
REVISION = "HEAD"
)

func VersionString() string {
build := time.Now()
// 暂时隐藏吧, 也不知道按啥version发布的好
// version := fmt.Sprintf("Version: %s\n", VERSION)
version := fmt.Sprintf("Git hash: %s\n", REVISION)
version += fmt.Sprintf("Built: %s\n", build.Format(time.RFC1123Z))
version += fmt.Sprintf("Golang version: %s\n", runtime.Version())
version += fmt.Sprintf("OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
return version
}

0 comments on commit 5ddb711

Please sign in to comment.