version

package
v0.0.0-...-0e9fed5 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 3 Imported by: 28

README

version

This is a simple version package to assist in returning a consistent version number for your program. It is inspired by https://github.com/tsaikd/KDGoLib own version package, but without all external dependencies.

This is a simple example on use:

package main

import (
	"fmt"
	"bitbucket.org/HelgeOlav/utils/version"
)

func init() {
	version.VERSION = "1.0.1" // whatever you want
	version.NAME = "myprog" // the name of your program
}

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

You can also add compile time constants on Linux/Mac using a compile-script like this:

githash="$(git rev-parse HEAD | cut -c1-8)"
buildtime="$(date +%Y-%m-%d)"

LDFLAGS="${LDFLAGS} -X bitbucket.org/HelgeOlav/utils/version.BUILDTIME=${buildtime}"
LDFLAGS="${LDFLAGS} -X bitbucket.org/HelgeOlav/utils/version.GITCOMMIT=${githash}"

go build -ldflags "${LDFLAGS}"

To compile on Windows you can use a script like this:

git rev-parse HEAD > hash.txt
date /t > date.txt
set /p GIT=<hash.txt
set /p STAMP=<date.txt

go build -ldflags="-X bitbucket.org/HelgeOlav/utils/version.BUILDTIME=%STAMP% -X bitbucket.org/HelgeOlav/utils/version.GITCOMMIT=%GIT%" .

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NAME      string    // name of program
	VERSION   = "0.0.0" // version of the program
	BUILDTIME string    // build-time of the compiled program
	GITCOMMIT string    // commit signature
	DEVSUFFIX = "-dev"  // appended to the version without a GITCOMMIT
)

exported variables

Functions

func AddModule

func AddModule(m ModuleVersion)

AddModule registers a new module

Types

type ModuleVersion

type ModuleVersion struct {
	Name      string `json:"name,omitempty"`      // name of the module
	Version   string `json:"version"`             // version of the module
	GitCommit string `json:"gitcommit,omitempty"` // commit hash, if available
}

ModuleVersion allows a module/plugin to register itself with a version number

type Version

type Version struct {
	Name      string          `json:"name,omitempty"`      // name of program
	Version   string          `json:"version"`             // version of the program
	GoVersion string          `json:"goversion"`           // go compiler
	BuildTime string          `json:"buildtime,omitempty"` // built time
	GitCommit string          `json:"gitcommit,omitempty"` // commit hash
	Modules   []ModuleVersion `json:"modules,omitempty"`   // a list of registered modules
}

func Get

func Get() (ver Version)

Get returns Version

func (Version) AllModules

func (v Version) AllModules() string

AllModules lists all modules with shortname/version

func (Version) LongString

func (t Version) LongString() string

LongString returns String() + (AllModules())

func (Version) SimpleVersion

func (v Version) SimpleVersion() string

SimpleVersion returns a version string like progname/version[-dev]

func (Version) String

func (t Version) String() string

String returns a string of the Version struct

Jump to

Keyboard shortcuts

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