Skip to content

Instantly share code, notes, and snippets.

@davidwkeith
Created September 27, 2018 17:31
Show Gist options
  • Save davidwkeith/c26b5ddf25ed09bf9cd293128253dced to your computer and use it in GitHub Desktop.
Save davidwkeith/c26b5ddf25ed09bf9cd293128253dced to your computer and use it in GitHub Desktop.
Convert go version strings to semver compliant strings
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