zoukankan      html  css  js  c++  java
  • go语言日期做版本号

    go语言开发程序,使用日期作为版本号。

    Makefile

    ❯ cat Makefile
    # -------------------------------
    # 编译脚本
    # -------------------------------
    
    BUILD_NAME         := bcpserv
    BUILD_VERSION      := 1.0.1.B.1
    BUILD_DATE         := $(shell date "+%y%m%d")
    BUILD_TIME         := $(shell date "+%F %T")
    BUILD_AUTHOR       := "john"
    
    all:
            go build -ldflags 
                    "-X '${BUILD_NAME}/version.Version=${BUILD_VERSION}.${BUILD_DATE}' 
                    -X '${BUILD_NAME}/version.Name=${BUILD_NAME}' 
                    -X '${BUILD_NAME}/version.BuildTime=${BUILD_TIME}' 
                    -X '${BUILD_NAME}/version.Author=${BUILD_AUTHOR}'"
    
    build:
            CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
    
    clean:
            rm -rf bcpserv
    
    help:
            @echo "make build - 编译 Go 代码, 生成Linux系统的二进制文件"
    

    go代码

    ❯ cat version/version.go
    package version
    
    import (
            "fmt"
            "os"
    )
    
    var (
            Name      = "nil"
            Version   = "nil"
            BuildTime = "nil"
            Author    = "nil"
    )
    
    func GetVersionInfo() string {
            ver := fmt.Sprintf("原始文件名: %s, 版本: %s, 构建时间: %s, 作者: %s", Name, Version, BuildTime, Author)
            return ver
    }
    
    func init() {
            args := os.Args
            if nil == args || len(args) < 2 {
                    return
            }
            if "-v" == args[1] {
                    fmt.Printf("Name: %s
    Version: %s
    BuildTime: %s
    Author: %s
    ", Name, Version, BuildTime, Author)
            } else if "-h" == args[1] {
                    fmt.Println("Usage:")
                    fmt.Printf("./%s
    ", Name)
                    fmt.Printf("./%s -v
    ", Name)
                    fmt.Printf("./%s -h
    ", Name)
            }
            os.Exit(0)
    }
    
    
  • 相关阅读:
    云计算安全之传统安全业务连续性和灾难恢复
    如何降低云应用程序的风险并管理其保障措施
    映射函数
    numpy用法
    dataframe基础
    list用法
    可视化基础
    pycharm使用技巧
    时间用法
    merge()函数
  • 原文地址:https://www.cnblogs.com/jiftle/p/14595439.html
Copyright © 2011-2022 走看看