version

package module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2023 License: MIT Imports: 2 Imported by: 0

README

golang app开发版本信息

引用模块

go get gitee.com/lyhuilin/version
#或
go get github.com/clin003/version

使用

package main

import (
	"fmt"

	"gitee.com/lyhuilin/version"
)

func main() {
	fmt.Println(version.APPVersion())
	fmt.Println(version.APPVersionEx())
	fmt.Println(version.APPDevInfo())
}

Makefile中用脚本参数


APP_GIT		:= app_git
APP          := app
DOCKER_IMAGE := baicailin/app
GO_MOD		:= gitee.com/lyhuilin/version
VERSION      := $(shell git describe --tags --abbrev=0)
COMMIT       := $(shell git rev-parse --short HEAD)
BUILD_DATE   := `date +%FT%T%z`
COMMIT_ID	:= `git log |head -n 1| awk '{print $2;}'`
AUTHOR		:= `git log |head -n 3| grep Author| awk '{print $2;}'`
BRANCH_NAME	:= `git branch | awk '/\*/ { print $2; }'`
LD_FLAGS     := "-s -w -X '$(GO_MOD).Version=$(VERSION)' -X '$(GO_MOD).Commit=$(COMMIT)' -X '$(GO_MOD).BuildDate=$(BUILD_DATE)'  -X '$(GO_MOD).Author=$(AUTHOR)'  -X '$(GO_MOD).BranchName=$(BRANCH_NAME)'  -X '$(GO_MOD).CommitId=$(COMMIT_ID)' "
DEB_IMG_ARCH := amd64

docker中用编译参数


  -X 'gitee.com/lyhuilin/version.Version=`git describe --tags --abbrev=0`' -X 'gitee.com/lyhuilin/version.Commit=`git rev-parse --short HEAD`' -X 'gitee.com/lyhuilin/version.BuildDate=`date +%FT%T%z`'   -X 'gitee.com/lyhuilin/version.Author=`git log |head -n 3| grep Author| awk '{print $2;}'`'  -X 'gitee.com/lyhuilin/version.BranchName=`git branch | awk '/\*/ { print $2; }'`'  -X 'gitee.com/lyhuilin/version.CommitId=`git log |head -n 1| awk '{print $2;}'`' 


Documentation

Overview

Package version contains application and build information.

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   = "dev"
	Commit    = "HEAD"
	BuildDate = "undefined" //编译时间

	Author     = "undefined" //作者信息
	BranchName = "undefined"
	CommitId   = "undefined"
)

Variables populated at build time.

Functions

func APPBuildInfo

func APPBuildInfo() string

func APPDevInfo

func APPDevInfo() string

func APPVersion

func APPVersion() string

func APPVersionEx

func APPVersionEx() string

func IsDev

func IsDev() bool

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL