ensure netclient version is compatible

This commit is contained in:
Matthew R. Kasun
2022-11-14 14:41:34 -05:00
parent 07eb6e3e6c
commit b453897e65
5 changed files with 80 additions and 0 deletions

31
logic/version.go Normal file
View File

@@ -0,0 +1,31 @@
package logic
import (
"strings"
"unicode"
"github.com/hashicorp/go-version"
)
const MinVersion = "v0.17.0"
// IsVersionCompatible checks that the version passed is compabtible (>=) with MinVersion
func IsVersionComptatible(ver string) bool {
// during dev, assume developers know what they are doing
if ver == "dev" {
return true
}
trimmed := strings.TrimFunc(ver, func(r rune) bool {
return !unicode.IsNumber(r)
})
v, err := version.NewVersion(trimmed)
if err != nil {
return false
}
constraint, err := version.NewConstraint(">= " + MinVersion)
if err != nil {
return false
}
return constraint.Check(v)
}