Created
September 27, 2018 17:31
-
-
Save davidwkeith/c26b5ddf25ed09bf9cd293128253dced to your computer and use it in GitHub Desktop.
Convert go version strings to semver compliant strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"runtime" | |
"strings" | |
"github.com/coreos/go-semver/semver" | |
) | |
func goVerAsSemVer() string { | |
version := strings.TrimPrefix(runtime.Version(), "go") | |
if len(strings.Split(version, ".")) != 3 { | |
version += ".0" | |
} | |
return version | |
} | |
func main() { | |
goVer := semver.New(goVerAsSemVer()) | |
minGoVer := semver.New("1.11.1") | |
if goVer.Compare(*minGoVer) < 0 { | |
fmt.Println("Not running minimum version of go, use polyfill code or error cleanly") | |
} else { | |
fmt.Println("Good to go") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment