add Makefile

This commit is contained in:
Ulric Qin 2022-05-29 17:37:57 +08:00
parent 2ef9930f8d
commit f9733e10d7
3 changed files with 21 additions and 2 deletions

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
.PHONY: start build
APP = categraf
VER = 0.1.0
all: build
build:
go build -ldflags "-w -s -X flashcat.cloud/categraf/config.Version=$(VER)"
pack:
env GOOS=linux GOARCH=amd64 go build -ldflags "-w -s -X flashcat.cloud/categraf/config.VERSION=$(VER)"
env GOOS=windows GOARCH=amd64 go build -ldflags "-w -s -X flashcat.cloud/categraf/config.VERSION=$(VER)"
rm -rf $(APP)-$(VER).tar.gz
rm -rf $(APP)-$(VER).zip
tar -zcvf $(APP)-$(VER).tar.gz conf $(APP)
zip -r $(APP)-$(VER).zip conf $(APP).exe

3
config/version.go Normal file
View File

@ -0,0 +1,3 @@
package config
var Version = "unknown"

View File

@ -21,7 +21,6 @@ import (
var (
appPath string
version = "0.1.0"
configDir = flag.String("configs", osx.GetEnv("CATEGRAF_CONFIGS", "conf"), "Specify configuration directory.(env:CATEGRAF_CONFIGS)")
debugMode = flag.Bool("debug", false, "Is debug mode?")
testMode = flag.Bool("test", false, "Is test mode? print metrics to stdout")
@ -51,7 +50,7 @@ func main() {
flag.Parse()
if *showVersion {
fmt.Println(version)
fmt.Println(config.Version)
os.Exit(0)
}