26 lines
589 B
Go
26 lines
589 B
Go
package versioncontract
|
|
|
|
import "strings"
|
|
|
|
// ValidStableVersion reports whether version uses the selected vMAJOR.MINOR.PATCH form.
|
|
func ValidStableVersion(version string) bool {
|
|
if !strings.HasPrefix(version, "v") {
|
|
return false
|
|
}
|
|
components := strings.Split(version[1:], ".")
|
|
if len(components) != 3 {
|
|
return false
|
|
}
|
|
for _, component := range components {
|
|
if component == "" || len(component) > 1 && component[0] == '0' {
|
|
return false
|
|
}
|
|
for i := 0; i < len(component); i++ {
|
|
if component[i] < '0' || component[i] > '9' {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|