version

package module
v0.0.0-...-756c961 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 5 Imported by: 0

README

version

go build with version

usage

# Makefile to build the command lines and tests in this project.
# This Makefile doesn't consider Windows Environment. If you use it in Windows, please be careful.

SHELL := /bin/bash

#BASEDIR = $(shell pwd)
BASEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))

# add following lines before go build!
versionDir = github.com/xwi88/version

gitBranch = $(shell git symbolic-ref --short -q HEAD)

ifeq ($(gitBranch),)
gitTag = $(shell git describe --always --tags --abbrev=0)
endif

buildTime = $(shell date "+%FT%T%z")
gitCommit = $(shell git rev-parse HEAD)
gitTreeState = $(shell if git status|grep -q 'clean';then echo clean; else echo dirty; fi)

# -ldflags flags accept a space-separated list of arguments to pass to an underlying tool during the build.
ldflags="-X ${versionDir}.gitBranch=${gitBranch} -X ${versionDir}.gitTag=${gitTag} \
 -X ${versionDir}.buildTime=${buildTime} -X ${versionDir}.gitCommit=${gitCommit} \
 -X ${versionDir}.gitTreeState=${gitTreeState}"

go build -ldflags ${ldflags}

Documentation

Overview

Build info for your project with arguments

Build and get info for your project

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	GitBranch    string `json:"git_branch"`
	GitTag       string `json:"git_tag"`
	GitCommit    string `json:"git_commit"`
	GitTreeState string `json:"git_tree_state"`
	BuildTime    string `json:"build_time"`
	Compiler     string `json:"compiler"`
	GoVersion    string `json:"go_version"`
	Platform     string `json:"platform"`
	ExecTime     string `json:"exec_time"`
}

Info contains version information.

func Get

func Get() Info

Get get the version info

func (Info) String

func (info Info) String() string

String returns info as a human-friendly json version string.

func (Info) StringWithIndent

func (info Info) StringWithIndent() string

String returns info as a human-friendly indent json version string.

Jump to

Keyboard shortcuts

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