diff --git a/Makefile b/Makefile index 27ad8c3..b9da8f6 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ -all=build BIN_NAME=go-pluginserver +VERSION?=development + +all: build build: - go build -ldflags="-s -w" -o $(BIN_NAME) -v + go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BIN_NAME) -v clean: rm -rf $(BIN_NAME) diff --git a/main.go b/main.go index 3c0ea71..321da09 100644 --- a/main.go +++ b/main.go @@ -4,17 +4,25 @@ package main import ( "flag" + "runtime" "github.com/ugorji/go/codec" "log" "net" "net/rpc" "os" "reflect" + "fmt" ) -var kongPrefix = flag.String("kong-prefix", "/usr/local/kong", "Kong prefix path (specified by the -p argument commonly used in the kong cli)") -var dump = flag.String("dump-plugin-info", "", "Dump info about `plugin` as a MessagePack object") -var pluginsDir = flag.String("plugins-directory", "", "Set directory `path` where to search plugins") +var version = "development" + +/* flags */ +var ( + kongPrefix = flag.String("kong-prefix", "/usr/local/kong", "Kong prefix path (specified by the -p argument commonly used in the kong cli)") + dump = flag.String("dump-plugin-info", "", "Dump info about `plugin` as a MessagePack object") + pluginsDir = flag.String("plugins-directory", "", "Set directory `path` where to search plugins") + showVersion = flag.Bool("version", false, "Print binary and runtime version") +) var socket string @@ -28,6 +36,10 @@ func init() { } } +func printVersion() { + fmt.Printf("Version: %s\nRuntime Version: %s\n", version, runtime.Version()) +} + func dumpInfo() { s := newServer() @@ -88,6 +100,11 @@ func startServer() { } func main() { + if *showVersion == true { + printVersion() + os.Exit(0) + } + if *dump != "" { dumpInfo() os.Exit(0)