Documentation
¶
Index ¶
- Constants
- func AddFlags(fs *pflag.FlagSet)
- func NewVersionFlag(name string, value versionValue, usage string) *versionValue
- func PrintAndExitIfRequested()
- func SetDynamicVersion(dynamicVersion string) error
- func ValidateDynamicVersion(dynamicVersion string) error
- func VersionVar(p *versionValue, name string, value versionValue, usage string)
- type Info
- type Version
- func (v *Version) AtLeast(minVersion *Version) bool
- func (v *Version) BuildMetadata() string
- func (v *Version) Compare(other string) (int, error)
- func (v *Version) Components() []uint
- func (v *Version) LessThan(other *Version) bool
- func (v *Version) Major() uint
- func (v *Version) Minor() uint
- func (v *Version) Patch() uint
- func (v *Version) PreRelease() string
- func (v *Version) String() string
- func (v *Version) WithBuildMetadata(buildMetadata string) *Version
- func (v *Version) WithMajor(major uint) *Version
- func (v *Version) WithMinor(minor uint) *Version
- func (v *Version) WithPatch(patch uint) *Version
- func (v *Version) WithPreRelease(preRelease string) *Version
Constants ¶
const ( // 未设置版本. VersionNotSet versionValue = 0 // 启用版本. VersionEnabled versionValue = 1 // 原始版本. VersionRaw versionValue = 2 )
定义一些常量.
Variables ¶
This section is empty.
Functions ¶
func NewVersionFlag ¶
NewVersionFlag 包装了 VersionVar 函数.
func PrintAndExitIfRequested ¶
func PrintAndExitIfRequested()
PrintAndExitIfRequested 将检查是否传递了 `--version` 标志,如果是,则打印版本并退出.
func SetDynamicVersion ¶
SetDynamicVersion overrides the version returned as the GitVersion from Get(). The specified version must be non-empty, a valid semantic version, and must match the major/minor/patch version of the default gitVersion.
func ValidateDynamicVersion ¶
ValidateDynamicVersion ensures the given version is non-empty, a valid semantic version, and matched the major/minor/patch version of the default gitVersion.
func VersionVar ¶
VersionVar 定义了一个具有指定名称和用法的标志.
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 包含了版本信息.
type Version ¶
type Version struct {
// contains filtered or unexported fields
}
Version is an opaque representation of a version number
func HighestSupportedVersion ¶
HighestSupportedVersion returns the highest supported version This function assumes that the highest supported version must be v1.x.
func MajorMinor ¶
MajorMinor returns a version with the provided major and minor version.
func MustParseGeneric ¶
MustParseGeneric is like ParseGeneric except that it panics on error
func MustParseSemantic ¶
MustParseSemantic is like ParseSemantic except that it panics on error
func ParseGeneric ¶
ParseGeneric parses a "generic" version string. The version string must consist of two or more dot-separated numeric fields (the first of which can't have leading zeroes), followed by arbitrary uninterpreted data (which need not be separated from the final numeric field by punctuation). For convenience, leading and trailing whitespace is ignored, and the version can be preceded by the letter "v". See also ParseSemantic.
func ParseSemantic ¶
ParseSemantic parses a version string that exactly obeys the syntax and semantics of the "Semantic Versioning" specification (http://semver.org/) (although it ignores leading and trailing whitespace, and allows the version to be preceded by "v"). For version strings that are not guaranteed to obey the Semantic Versioning syntax, use ParseGeneric.
func (*Version) AtLeast ¶
AtLeast tests if a version is at least equal to a given minimum version. If both Versions are Semantic Versions, this will use the Semantic Version comparison algorithm. Otherwise, it will compare only the numeric components, with non-present components being considered "0" (ie, "1.4" is equal to "1.4.0").
func (*Version) BuildMetadata ¶
BuildMetadata returns the build metadata, if v is a Semantic Version, or ""
func (*Version) Compare ¶
Compare compares v against a version string (which will be parsed as either Semantic or non-Semantic depending on v). On success it returns -1 if v is less than other, 1 if it is greater than other, or 0 if they are equal.
func (*Version) Components ¶
Components returns the version number components
func (*Version) LessThan ¶
LessThan tests if a version is less than a given version. (It is exactly the opposite of AtLeast, for situations where asking "is v too old?" makes more sense than asking "is v new enough?".)
func (*Version) PreRelease ¶
PreRelease returns the prerelease metadata, if v is a Semantic Version, or ""
func (*Version) String ¶
String converts a Version back to a string; note that for versions parsed with ParseGeneric, this will not include the trailing uninterpreted portion of the version number.
func (*Version) WithBuildMetadata ¶
WithBuildMetadata returns copy of the version object with requested buildMetadata
func (*Version) WithMajor ¶
WithMajor returns copy of the version object with requested major number
func (*Version) WithMinor ¶
WithMinor returns copy of the version object with requested minor number
func (*Version) WithPatch ¶
WithPatch returns copy of the version object with requested patch number
func (*Version) WithPreRelease ¶
WithPreRelease returns copy of the version object with requested prerelease