Giter VIP home page Giter VIP logo

goversion's Introduction

goversion

为 golang 应用程序编译加入版本信息

原理

使用 go build -ldflags "", 可以根据自己需要进行调整。

使用方法

  1. 将example中的 Makefile copy 到 main 函数 所在的目录
  2. 修改 Makefile 中的 目标生成文件名称
  3. 每次发布时,手动调整 Makefile 中的版本信息
  4. 在 shell 中执行 make or make build

注意事项

见 example 示例中的Makefile

源代码使用示例

package main

import (
	"flag"
	"fmt"

	"github.com/lovestreet/goversion" 
)

var loglevel = flag.String("loglevel", "false", "the level of log")

func main() {
	flag.Parse()

	//[[ 代码集成
	//show version and exist, if have -v or -version
	goversion.ShowAndExit()
	//]]

	//do your code
	fmt.Printf("loglevel = %v", *loglevel)
}

goversion's People

Contributors

lovestreet avatar

Stargazers

soidea avatar cwenzhong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.