Documentation ¶
Overview ¶
Package version provides methods for working with semver version info
Index ¶
- Variables
- type Version
- func (v Version) Build() string
- func (v Version) Contains(version Version) bool
- func (v Version) Equal(version Version) bool
- func (v Version) Greater(version Version) bool
- func (v Version) Int() int
- func (v Version) IsZero() bool
- func (v Version) Less(version Version) bool
- func (v Version) Major() int
- func (v Version) Minor() int
- func (v Version) Patch() int
- func (v Version) PreRelease() string
- func (v Version) Simple() string
- func (v Version) String() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrEmpty is returned is given version is empty ErrEmpty = errors.New("Version can't be empty") // ErrEmptyBuild is returned if build number is empty ErrEmptyBuild = errors.New("Build number is empty") // ErrEmptyPrerelease is returned is prerelease number is empty ErrEmptyPrerelease = errors.New("Prerelease number is empty") )
Functions ¶
This section is empty.
Types ¶
type Version ¶
type Version struct {
// contains filtered or unexported fields
}
Version contains version data
func Parse ¶
Parse parses version string and return version struct
Example ¶
v, err := Parse("6.12.1-beta2+exp.sha.5114f85") if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("Major: %d\n", v.Major()) fmt.Printf("Minor: %d\n", v.Minor()) fmt.Printf("Patch: %d\n", v.Patch()) fmt.Printf("PreRelease: %s\n", v.PreRelease()) fmt.Printf("Build: %s\n", v.Build())
Output: Major: 6 Minor: 12 Patch: 1 PreRelease: beta2 Build: exp.sha.5114f85
func (Version) Build ¶
Build returns build string
Example ¶
v, _ := Parse("4.12.7+2f6c6ea6287d2f14") fmt.Println(v.Build())
Output: 2f6c6ea6287d2f14
func (Version) Contains ¶
Contains checks is current version contains given version
Example ¶
v1, _ := Parse("1.0") v2, _ := Parse("1.0.1") v3, _ := Parse("1.1") fmt.Printf("%s contains %s → %t\n", v1.String(), v2.String(), v1.Contains(v2)) fmt.Printf("%s contains %s → %t\n", v1.String(), v3.String(), v1.Contains(v3))
Output: 1.0 contains 1.0.1 → true 1.0 contains 1.1 → false
func (Version) Equal ¶
Equal return true if version are equal to given
Example ¶
v1, _ := Parse("1") v2, _ := Parse("1.0.0") v3, _ := Parse("1.0.1") fmt.Printf("%s = %s → %t\n", v1.String(), v2.String(), v1.Equal(v2)) fmt.Printf("%s = %s → %t\n", v1.String(), v3.String(), v1.Equal(v3))
Output: 1 = 1.0.0 → true 1 = 1.0.1 → false
func (Version) Greater ¶
Greater returns true if given version is less
Example ¶
v1, _ := Parse("1") v2, _ := Parse("1.0.0") v3, _ := Parse("1.0.1") fmt.Printf("%s > %s → %t\n", v1.String(), v2.String(), v1.Greater(v2)) fmt.Printf("%s > %s → %t\n", v3.String(), v1.String(), v3.Greater(v1))
Output: 1 > 1.0.0 → false 1.0.1 > 1 → true
func (Version) Int ¶
Int returns version as integer
Example ¶
v, _ := Parse("14.8.22") fmt.Println(v.Int())
Output: 14008022
func (Version) Less ¶
Less returns true if given version is greater
Example ¶
v1, _ := Parse("1") v2, _ := Parse("1.0.0") v3, _ := Parse("1.0.1") fmt.Printf("%s < %s → %t\n", v1.String(), v2.String(), v1.Less(v2)) fmt.Printf("%s < %s → %t\n", v1.String(), v3.String(), v1.Less(v3))
Output: 1 < 1.0.0 → false 1 < 1.0.1 → true
func (Version) Major ¶
Major returns major version
Example ¶
v, _ := Parse("4.12.7") fmt.Println(v.Major())
Output: 4
func (Version) Minor ¶
Minor returns minor version
Example ¶
v, _ := Parse("4.12.7") fmt.Println(v.Minor())
Output: 12
func (Version) Patch ¶
Patch returns patch version
Example ¶
v, _ := Parse("4.12.7") fmt.Println(v.Patch())
Output: 7
func (Version) PreRelease ¶
PreRelease returns prerelease version
Example ¶
v, _ := Parse("4.12.7-rc1") fmt.Println(v.PreRelease())
Output: rc1
Click to show internal directories.
Click to hide internal directories.