package version import ( "fmt" "os" "time" //"os" ) var ( SERVICE_VERSION = "V2.001" //以下几个字段编译期间自动替换,无需手动操作 GIT_BRANCH = "GIT_BRANCH_FLAG" GIT_VERSION = "GIT_VERSION_FLAG" BUILD_DATE = "BUILD_DATE_FLAG" BUILD_IP = "BUILD_IP_FLAG" ) var ( ServerStartTime = time.Now() ServerStartLast = time.Time{} ServerAliveLast = time.Time{} ServerCloseLast = time.Time{} ) func Info() { fmt.Printf("version:%s\n", SERVICE_VERSION) fmt.Printf("git branch:%s\n", GIT_BRANCH) fmt.Printf("git version:%s\n", GIT_VERSION) fmt.Printf("build date:%s\n", BUILD_DATE) fmt.Printf("build ip:%s\n", BUILD_IP) os.Exit(0) //退出进程 } func GetVersion() *Version { return &Version{ ServiceVer: SERVICE_VERSION, GitVer: GIT_VERSION, BuildDate: BUILD_DATE, BuildIp: BUILD_IP, Branch: GIT_BRANCH, } } type Version struct { ServiceVer string `json:"serviceVer"` GitVer string `json:"gitVer"` BuildDate string `json:"buildDate"` BuildIp string `json:"buildIp"` Branch string `json:"branch"` } func HostName() string { name, _ := os.Hostname() return name }