-
Notifications
You must be signed in to change notification settings - Fork 3
/
semver.go
36 lines (30 loc) · 919 Bytes
/
semver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) 2016 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package semver
import "fmt"
// NewSemver returns a new Semver with the version major.minor.patch
func NewSemver(major, minor, patch uint32) Semver {
return Semver{major, minor, patch}
}
// Semver models a semantic version (semver) major.minor.patch
type Semver struct {
major, minor, patch uint32
}
// SemverCompatible evaluates if the versions passed are compatible and returns a
// bool
func SemverCompatible(required, actual Semver) bool {
switch {
case required.major != actual.major:
return false
case required.minor > actual.minor:
return false
case required.minor == actual.minor && required.patch > actual.patch:
return false
default:
return true
}
}
func (s Semver) String() string {
return fmt.Sprintf("%d.%d.%d", s.major, s.minor, s.patch)
}