{"id":20256359,"url":"https://github.com/k0sproject/version","last_synced_at":"2025-04-11T00:21:53.363Z","repository":{"id":42192074,"uuid":"456490005","full_name":"k0sproject/version","owner":"k0sproject","description":"A golang package for comparing and working with k0s version numbers","archived":false,"fork":false,"pushed_at":"2025-02-26T09:29:13.000Z","size":79,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-24T21:06:26.533Z","etag":null,"topics":["go","k0s","semantic-version"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/k0sproject.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-07T12:09:21.000Z","updated_at":"2025-02-26T09:29:15.000Z","dependencies_parsed_at":"2024-02-13T08:26:59.204Z","dependency_job_id":"d0d3919d-5a6e-4b46-b41e-7a1636aa8a22","html_url":"https://github.com/k0sproject/version","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k0sproject%2Fversion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k0sproject%2Fversion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k0sproject%2Fversion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k0sproject%2Fversion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/k0sproject","download_url":"https://codeload.github.com/k0sproject/version/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248318928,"owners_count":21083751,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","k0s","semantic-version"],"created_at":"2024-11-14T10:46:23.223Z","updated_at":"2025-04-11T00:21:53.334Z","avatar_url":"https://github.com/k0sproject.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# version\n\nA go-language package for parsing, comparing, sorting and constraint-checking [k0s](https://github.com/k0sproject/k0s) version numbers. The API is modeled after [hashicorp/go-version](https://github.com/hashicorp/go-version). \n\nK0s versioning follows [semver](https://semver.org/) v2.0 with the exception that there is a special metadata field for the k0s build version like `v1.23.4+k0s.1` which affects precedence while sorting or comparing version numbers.\n\nThe library should work fine for performing the same operations on non-k0s version numbers as long as there are maximum of 3 numeric segments (1.2.3), but this is not a priority. There are no dependencies.\n\n## Usage\n\n### Basic comparison\n\n```go\nimport (\n\t\"fmt\"\n\n\t\"github.com/k0sproject/version\"\n)\n\nfunc main() {\n\ta := version.MustParse(\"1.23.3+k0s.1\")\n\tb := version.MustParse(\"1.23.3+k0s.2\")\n\tfmt.Printf(\"a is greater than b: %t\\n\", a.GreaterThan(b))\n\tfmt.Printf(\"a is less than b: %t\\n\", a.LessThan(b))\n\tfmt.Printf(\"a is equal to b: %t\\n\", a.Equal(b))\n}\n```\n\nOutputs:\n\n```text\na is greater than b: false\na is less than b: true\na is equal to b: false\n```\n\n### Constraints\n\n```go\nimport (\n\t\"fmt\"\n\n\t\"github.com/k0sproject/version\"\n)\n\nfunc main() {\n\tv := version.MustParse(\"1.23.3+k0s.1\")\n\tc := version.MustConstraint(\"\u003e 1.23\")\n    fmt.Printf(\"constraint %s satisfied by %s: %t\\n\", c, v, c.Check(v))\n}\n```\n\nOutputs:\n\n```text\nconstraint \u003e 1.2.3 satisfied by v1.23.3+k0s.1: true\n```\n\n### Sorting\n\n```go\nimport (\n\t\"fmt\"\n    \"sort\"\n\n\t\"github.com/k0sproject/version\"\n)\n\nfunc main() {\n    versions := []*version.Version{\n\t    version.MustParse(\"v1.23.3+k0s.2\"),\n        version.MustParse(\"1.23.2+k0s.3\"),\n        version.MustParse(\"1.23.3+k0s.1\"),\n    }\n\n    fmt.Println(\"Before:\")\n    for _, v range versions {\n        fmt.Println(v)\n    }\n    sort.Sort(versions)\n    fmt.Println(\"After:\")\n    for _, v range versions {\n        fmt.Println(v)\n    }\n}\n```\n\nOutputs:\n\n```text\nBefore:\nv1.23.3+k0s.2\nv1.23.2+k0s.3\nv1.23.3+k0s.1\nAfter:\nv1.23.2+k0s.3\nv1.23.3+k0s.1\nv1.23.3+k0s.2\n```\n\n### Check online for latest version\n\n```go\nimport (\n\t\"fmt\"\n\t\"github.com/k0sproject/version\"\n)\n\nfunc main() {\n\tlatest, err := version.Latest()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"Latest k0s version is: %s\\n\", latest)\n}\n```\n\n### `k0s_sort` executable\n\nA command-line interface to the package. Can be used to sort lists of versions or to obtain the latest version number.\n\n```console\nUsage: k0s_sort [options] [filename ...]\n  -l\tonly print the latest version\n  -o\tprint the latest version from online\n  -s\tomit prerelease versions\n  -v\tprint k0s_sort version\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk0sproject%2Fversion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fk0sproject%2Fversion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk0sproject%2Fversion/lists"}