version

package module
v0.0.0-...-90f89e6 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: MIT Imports: 4 Imported by: 0

README

version

Project version management pkg.

Usage

Go:

import "github.com/go-project-pkg/version"

func main() {
  fmt.Println(version.Get())
}

Shell:

VERSION_PACKAGE=github.com/go-project-pkg/version
VERSION=$(git describe --tags --always --match='v*')
GIT_COMMIT=$(git rev-parse HEAD)
GIT_TREE_STATE=dirty

if git status --porcelain 2>/dev/null;then
    GIT_TREE_STATE=clean
fi

LDFLAGS="-X $VERSION_PACKAGE.GitVersion=$VERSION
        -X $VERSION_PACKAGE.GitCommit=$GIT_COMMIT
        -X $VERSION_PACKAGE.GitTreeState=$GIT_TREE_STATE
        -X $VERSION_PACKAGE.BuildDate=$(date -u +'%Y-%m-%dT%H:%M:%SZ')"

go build -tags=jsoniter -ldflags "$LDFLAGS"
    -o _output/your-project-binaryname ./your/project/maingo/path

You can use scripts/build.sh to build the project.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GitVersion is semantic version.
	GitVersion = "v0.0.0-master+$Format:%h$"
	// BuildDate in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ').
	BuildDate = "1970-01-01T00:00:00Z"
	// GitCommit sha1 from git, output of $(git rev-parse HEAD).
	GitCommit = "$Format:%H$"
	// GitTreeState state of git tree, either "clean" or "dirty".
	GitTreeState = ""
)

Functions

This section is empty.

Types

type Info

type Info struct {
	GitVersion   string `json:"gitVersion"`
	GitCommit    string `json:"gitCommit"`
	GitTreeState string `json:"gitTreeState"`
	BuildDate    string `json:"buildDate"`
	GoVersion    string `json:"goVersion"`
	Compiler     string `json:"compiler"`
	Platform     string `json:"platform"`
}

Info contains versioning information.

func Get

func Get() Info

Get returns the overall codebase version. It's for detecting what code a binary was built from.

func (Info) String

func (info Info) String() string

String returns info as a human-friendly version string.

func (Info) Text

func (info Info) Text() ([]byte, error)

Text encodes the version information into UTF-8-encoded text and returns the result.

func (Info) ToJSON

func (info Info) ToJSON() string

ToJSON returns the JSON string of version information.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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