goversion

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: MIT Imports: 6 Imported by: 0

README

GoVersion    GitHub release (latest SemVer)  GitHub Workflow Status

Go Reference

A (very) simple go package for handling semver compliant application versions.


Features

  • Immutable application version, set via linker flags.
  • Values from runtime/debug available.
  • Check for updates using public GitHub release/tag information.

Usage

Somewhere in your application, be sure that this package is imported:

import (
  _ "github.com/neaas/go-version"
)

Configuration

Set each configuration value using the linker flags as described below:

go build -ldflags "-X github.com/neaas/go-version.VARIABLE=VALUE" .
Variable Description Default Value
version The semver compliant version of the application being built. v0.0.0+unversioned
repositoryOwner The owner of the GitHub repository for the application. neaas
repositoryName The name of the application's GitHub repository. go-version
versionType The method in which versions are defined for the repository
(release, tag, none)
tag

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build() string

Build returns the build metadata value of the version if any. The '+' prefix is stripped.

func DepVersion

func DepVersion(modulePath string) string

DepVersion returns the version of a given dependency used. If the given dependency was not used, an empty string is returned. This does not guarantee a semver compliant response.

func Equal

func Equal(v string) bool

Equal returns true if the application version is equal to version v.

func GoVersion

func GoVersion() string

GoVersion returns the golang version that was used to build the application. This does not guarantee a semver compliant response.

func GreaterThan

func GreaterThan(v string) bool

GreaterThan returns true if the application version is greater than v.

func GreaterThanEqual

func GreaterThanEqual(v string) bool

GreaterThanEqual returns true if the application version is greater than or equal to version v.

func IsUnversioned

func IsUnversioned() bool

IsUnversioned returns true if the version is the default unversioned string. This is likely to be true in development builds.

func IsValid

func IsValid() bool

IsValid returns true if the version is in a state that is compatible with this package. This can be used to prevent invalid versions from being set.

func LatestVersion

func LatestVersion(versions []string) string

LatestVersion determines the latest version that is valid semver and not prerelease from a given set of version strings. If no string provided fits this criteria, an empty string is returned. There is no requirement for the versions to be sorted prior to calling. Can be used in conjunction with Versions and RepoVersions.

func LessThan

func LessThan(v string) bool

LessThan returns true if the application version is less than version v.

func LessThanEqual

func LessThanEqual(v string) bool

LessThanEqual returns true if the application version is less than or equal to version v.

func Prerelease

func Prerelease() string

Prerelease returns the prerelease value of the version if any. The '-' prefix is stripped.

func RepoVersions

func RepoVersions(owner, name, versionType string) ([]string, error)

RepoVersions fetches all of the releases/tags from the GitHub repository with the owner and name provided and reports back all the semver compliant tag names coupled with them. This only errors if the release or tag list could not be fetched.

func Update

func Update(latest string) bool

Update checks if the current application's version is lower than that of the version provided (only if the provided version is semver compliant). If the application's version is lower, Update will return true. If the application's version is equal to or greater than the given version, Update will return false. If the given version is not semver compliant, Update will return false.

func VCSCommit

func VCSCommit() string

VCSCommit returns the version control system commit associated with the application's binary.

func Version

func Version() string

Version returns the canonically formatted semver compliant version string (with the 'v' prefix) or the default unversioned string.

func Versions

func Versions() ([]string, error)

Versions fetches all of the releases/tags from the application's associated GitHub repository and reports back all the semver compliant tag names coupled with them. This only errors if the release or tag list could not be fetched.

Types

This section is empty.

Jump to

Keyboard shortcuts

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