github.com/sandwich-go/boost@v1.3.29/version/README.md (about)

     1  # version
     2  
     3  编译时,记录程序版本相关信息
     4  
     5  # 例子
     6  ```shell
     7  version=$( git rev-parse --short HEAD 2> /dev/null || echo 'unknown' )
     8  revision='alpha'
     9  branch=$( git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown' )
    10  BUILD_USER=${BUILD_USER:-"${USER}@${HOSTNAME}"}
    11  BUILD_DATE=${BUILD_DATE:-$( date +%Y%m%d-%H:%M:%S )}
    12  
    13  build_info="-X github.com/sandwich-go/boost/version.BuildDate=$BUILD_DATE"
    14  build_info="$build_info -X github.com/sandwich-go/boost/version.Revision=$revision"
    15  build_info="$build_info -X github.com/sandwich-go/boost/version.Branch=$branch"
    16  build_info="$build_info -X github.com/sandwich-go/boost/version.BuildUser=$BUILD_USER"
    17  build_info="$build_info -X github.com/sandwich-go/boost/version.Version=$version"
    18  
    19  go build -ldflags "$build_info" -o xxxxxx/main.go
    20  ```