# goodash **Repository Path**: edodo/goodash ## Basic Information - **Project Name**: goodash - **Description**: go语言实现的底层类库 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-03 - **Last Updated**: 2025-10-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 实践优化 ### 1.版本号内置在程序里面,运行和部署程序的时候,可以用来知晓当前发布和部署的程序是什么版本 #### 1.1 入口 main.go ```go package main import ( "flag" "fmt" ) var ( GitTag = "2000.01.01.release" BuildTime = "2000-01-01T00:00:00+0800" ) func main() { version := flag.Bool("v", false, "version") flag.Parse() if *version { fmt.Println("Git Tag: " + GitTag) fmt.Println("Build Time: " + BuildTime) } } ``` #### 1.2 Makefile ```makefile # This is how we want to name the binary output OUTPUT=main # These are the values we want to pass for Version and BuildTime GITTAG=`git describe --tags` BUILD_TIME=`date +%FT%T%z` # Setup the -ldflags option for go build here, interpolate the variable values LDFLAGS=-ldflags "-X main.GitTag=${GITTAG} -X main.BuildTime=${BUILD_TIME}" all: go build ${LDFLAGS} -o ${OUTPUT} main.go ``` #### 1.3 程序部署的时候,通过git tag取代码,直接 make all就可以了。