Documentation
¶
Index ¶
- type Core
- func (c Core) Compare(u Core) int
- func (c Core) Component() [4]uint16
- func (c Core) Int64() int64
- func (c Core) MarshalJSON() ([]byte, error)
- func (c Core) MarshalText() ([]byte, error)
- func (c Core) Nums() []uint
- func (c Core) String() string
- func (c *Core) UnmarshalJSON(data []byte) error
- func (c *Core) UnmarshalText(text []byte) error
- type Version
- func (v Version) Build() string
- func (v Version) Compare(u Version) int
- func (v Version) Core() Core
- func (v Version) MarshalJSON() ([]byte, error)
- func (v Version) MarshalText() ([]byte, error)
- func (v Version) PreRelease() string
- func (v Version) String() string
- func (v *Version) UnmarshalJSON(data []byte) error
- func (v *Version) UnmarshalText(text []byte) error
- func (v Version) V() bool
- func (v Version) WithBuild(buildMeta string) (Version, error)
- func (v Version) WithCore(core Core) Version
- func (v Version) WithPreRelease(prerelease string) (Version, error)
- func (v Version) WithV(vFlag bool) Version
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core represents only numeric part of Version.
The number of version fields may vary based on input between `a` to `a.b.c.d`. Each field is limited up to 9999.
The zero value of Core is invalid and must be initialized with NewCore or ParseCore. However calling Core.String with zero value returns `"0.0.0"` and works fine almost all situation.
func MustNewCore ¶
MustNewCore is like NewCore but panics if an error occurs.
func MustParseCore ¶
MustParseCore is like ParseCore but panics if any error occurs.
func NewCore ¶
NewCore initializes Core. len(nums) must be between 1 and 4. If any component of nums are greater than 9999, it returns an error.
func ParseCore ¶
ParseCore parses string expression and returns Core. s must be dot-separated numeric values without leading zeros. Similar rules to NewCore apply here: the number of version fields must be in between 1 to 4 and each version component must not be greater than 9999.
func (Core) Compare ¶
Compare returns
-1 if c is less than u, 0 if c equals u, +1 if c is greater than u.
Missing parts are always treated as 0. e.g. comparing 1 and 1.0 returns 0, 1.0.0.2 and 1.0 returns +1.
func (Core) Int64 ¶
Int64 returns version fields as int64 value. The conversion logic is roghly same of `strconv.ParseInt(fmt.Sprintf("%04d%04d%04d%04d", a, b, c, d), 10, 64)` but more efficient.
func (Core) MarshalJSON ¶
func (Core) MarshalText ¶
func (Core) Nums ¶
Nums returns version fields as slice of uint. The length of the return value may vary on input, e.g. if input was `1` then Nums returns []uint{1}, if was `1.2.3.4`, it returns []uint{1, 2, 3, 4}.
func (Core) String ¶
String returns string representation of the version. If c is zero, it returns `"0.0.0"`.
func (*Core) UnmarshalJSON ¶
func (*Core) UnmarshalText ¶
type Version ¶
type Version struct {
// contains filtered or unexported fields
}
Version is an implementaion of semantic versioning v2 but with slight extensions. The general form of a semantic version string accepted by Version is
[v]A[.B[.C[.D][-PRERELEASE][+BUILD]]
- `v` prefix is optionally allowed
- One extra version field (`D`) is also allowed
- Each version fields are limited to 9999.
- pre-release and build-meta is only allowed when the verions is full (has `C`) or extended (has `D`).
func MustParse ¶
MustParse is like Parse but panics when s is not accepted as the extended version string.
func (Version) Build ¶
Build returns build-meta string. The retunred value is empty if v is not suffixed with build-meta.
func (Version) Compare ¶
Compare returns
-1 if v is less than u, 0 if v equals u, +1 if v is greater than u.
Unlike Core.Compare, the number of version fields affects ordering: if cores and pre-release of both v and u are semantically same, the shorter one is considered less. e.g. 1.0 is less than 1.0.0.
The pre-release values are compared as per spec. see https://semver.org/#spec-item-11
func (Version) MarshalJSON ¶
func (Version) MarshalText ¶
func (Version) PreRelease ¶
PreRelease returns pre-release string. The returned value is empty if v is not suffixed with pre-prelease.
func (*Version) UnmarshalJSON ¶
func (*Version) UnmarshalText ¶
func (Version) WithBuild ¶
WithBuild returns v with build-meta value is changed to the input. If the input is not compliant to the spec, it returns unmodified v and an non-nil error.
func (Version) WithPreRelease ¶
WithPreRelease returns v with pre-prelease value is changed to the input. If the input is not compliant to the spec, it returns unmodified v and an non-nil error.