$ go run .
hashicorp/go-version: 1.2.1 (~>1.1): true
Masterminds/semver: 1.2.1 (~>1.1): false
Last active
May 8, 2024 20:45
-
-
Save mckern/ad65c951a09a828de5905b0bbbab5b7e to your computer and use it in GitHub Desktop.
Semver library constraint comparison
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
module github.com/mckern/clownshoes | |
go 1.22 | |
require github.com/hashicorp/go-version v1.6.0 | |
require github.com/Masterminds/semver/v3 v3.2.1 |
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" | |
"github.com/Masterminds/semver/v3" | |
"github.com/hashicorp/go-version" | |
) | |
const ( | |
ver = "1.2.1" | |
con = "~>1.1" | |
) | |
func main() { | |
vh, _ := version.NewVersion(ver) | |
ch, _ := version.NewConstraint(con) | |
fmt.Printf("hashicorp/go-version: %s (%s): %v\n", | |
vh, ch, ch.Check(vh)) | |
vs, _ := semver.NewVersion(ver) | |
cs, _ := semver.NewConstraint(con) | |
fmt.Printf("Masterminds/semver: %s (%s): %v\n", | |
vs, cs, cs.Check(vs)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment