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 30, 2023 License: Apache-2.0 Imports: 7 Imported by: 12

README

go-version

This package is extracted from sigs.k8s.io/release-utils.

There were a couple of subtle changes made, so it has 0 dependencies and can be used with anything.

Credits goes to the Kubernetes Authors.

Changes

Full list of changes from the original library:

  • drop all dependencies:
    • use std testing only
    • allow to pass a previously generated ASCII art instead of generating it at runtime
  • optional overrides:
    • caller can pass one or more functions that change the version info, so callers are free to use whatever methods they want to provide some options
    • a range of functions are provided by the library
  • added more fields:
    • URL
    • BuiltBy
  • testing
    • added more tests, hopefully preventing breaking changes in the future

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

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

	ASCIIName   string `json:"-"`
	Name        string `json:"-"`
	Description string `json:"-"`
	URL         string `json:"-"`
}

Info provides the version info.

func GetVersionInfo

func GetVersionInfo(options ...Option) Info

GetVersionInfo represents known information on how this binary was built.

func (*Info) JSONString

func (i *Info) JSONString() (string, error)

JSONString returns the JSON representation of the version info

func (Info) String

func (i Info) String() string

String returns the string representation of the version info

type Option

type Option func(i *Info)

Option can be used to customize the version after its gathered from the environment.

func WithASCIIName

func WithASCIIName(name string) Option

WithASCIIName allows you to add an ASCII art of the name.

func WithAppDetails

func WithAppDetails(name, description, url string) Option

WithAppDetails allows to set the app name and description.

func WithBuiltBy

func WithBuiltBy(name string) Option

WithBuiltBy allows to set the builder name/builder system name.

Jump to

Keyboard shortcuts

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