initial version parsing

This commit is contained in:
Paul Fey 2025-07-26 11:06:27 +02:00
parent 2cd9866eca
commit 9ac93995bd
3 changed files with 41 additions and 0 deletions

2
go.mod
View file

@ -1,3 +1,5 @@
module git.pauljako.de/rodeo/rodeo-pkg
go 1.24.3
require github.com/apparentlymart/go-versions v1.0.3

8
go.sum Normal file
View file

@ -0,0 +1,8 @@
github.com/apparentlymart/go-versions v1.0.3 h1:T3b8tumoQLuu1dej2Y9v22J4PWV9IzDLh2A9lIPoVSM=
github.com/apparentlymart/go-versions v1.0.3/go.mod h1:YF5j7IQtrOAOnsGkniupEA5bfCjzd7i14yu0shZavyM=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-test/deep v1.0.1 h1:UQhStjbkDClarlmv0am7OXXO4/GaPdCGiUiMTvi28sg=
github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=

View file

@ -0,0 +1,31 @@
package resolver
import (
"github.com/apparentlymart/go-versions/versions"
)
func GetBest(allVersions []string, requirement string) (string, error) {
available := versions.List{}
for _, versionString := range allVersions {
versionObject, err := versions.ParseVersion(versionString)
if err != nil {
return "", err
}
available = append(available, versionObject)
}
allowed, err := versions.MeetingConstraintsString(requirement)
if err != nil {
return "", err
}
candidates := available.Filter(allowed)
chosen := candidates.Newest()
best := string(chosen)
return best, nil
}