forked from coop-cloud/tagcmp
Add example
This commit is contained in:
parent
5e63b39311
commit
5982269b37
48
README.md
48
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)
|
||||
|
|
Loading…
Reference in New Issue