Categorygithub.com/patrickjmcd/go-version
modulepackage
0.0.0-20220126201046-52be7ddbba40
Repository: https://github.com/patrickjmcd/go-version.git
Documentation: pkg.go.dev

# README

Go Version Package Printer

A simple package to show commit, version, and build time for a go program

Usage

In your program, include github.com/patrickjmcd/go-version.

In your main.go file's main function, include

fmt.Println(version.GetVersion())

When you build your program, build using a command like:

go build \
  -ldflags "-s -w -X github.com/patrickjmcd/go-version/version.Release=${RELEASE} \
  -X github.com/patrickjmcd/go-version/version.Commit=${COMMIT} -X github.com/patrickjmcd/go-version/version.BuildTime=${BUILD_TIME}" \
  -o ${APP}

Example

Create a main.go file with the following contents:

package main

import (
  "log"

  "github.com/patrickjmcd/go-version"
)

func main() {
  log.Printf(
    "Starting the test...\n%s",
    version.GetVersion(),
  )
}

Build the executable with the following command:

go build \
  -ldflags "-s -w -X github.com/patrickjmcd/go-version/version.Release=0.0.1 \
  -X github.com/patrickjmcd/go-version/version.Commit=aabbddcceeff -X github.com/patrickjmcd/go-version/version.BuildTime=2021-11-09_21:18:54 \
  -o testversion

Run the executable and see the output!

$ ./testversion
Starting the test...
commit: aabbddcceeff, build time: 2021-11-09_21:18:54, release: 0.0.1

# Functions

No description provided by the author

# Variables

BuildTime is a time label of the moment when the binary was built.
Commit is a last commit hash at the moment when the binary was built.
Release is a semantic version of current build.