From 5982269b3747e6a28f89476cbacc69cc3378d77c Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sun, 8 Aug 2021 19:15:15 +0200 Subject: [PATCH] Add example --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/README.md b/README.md index 5860c5a..15e8386 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,54 @@ implementation quite closely. [renovate]: https://github.com/renovatebot/renovate/blob/main/lib/versioning/docker/readme.md [renovate implementation]: https://github.com/renovatebot/renovate/tree/main/lib/datasource/docker +## Example + +```golang +package main + +import ( + "fmt" + "sort" + + "coopcloud.tech/tagcmp" +) + +func main() { + rawTags := []string{ + "1.7.1", + "1.9.4-linux-arm64", + "1.14.0-rootless", + "linux-arm64-rootless", + "1.14.1-rootless", + "1.12.4-linux-amd64", + "1.14.2-rootless", + } + + tag, err := tagcmp.Parse("1.14.0-rootless") + if err != nil { + panic(err) + } + + var compatible []tagcmp.Tag + for _, rawTag := range rawTags { + parsed, _ := tagcmp.Parse(rawTag) // skipped unsupported tags + if tag.IsCompatible(parsed) { + compatible = append(compatible, parsed) + } + } + + sort.Sort(tagcmp.ByTag(compatible)) + + fmt.Println(compatible) +} +``` + +Output: + +```golang +[1.14.0-rootless 1.14.1-rootless 1.14.2-rootless] +``` + ## Documentation [godoc.md](./godoc.md)