top

Package semver provides the ability to work with Semantic Versions (http://semver.org) in Go.

Specifically it provides the ability to:

* Parse semantic versions
* Sort semantic versions
* Check if a semantic version fits within a set of constraints
* Optionally work with a `v` prefix

Parsing Semantic Versions

To parse a semantic version use the `NewVersion` function. For example,

v, err := semver.NewVersion("1.2.3-beta.1+build345")

If there is an error the version wasn't parseable. The version object has methods to get the parts of the version, compare it to other versions, convert the version back into a string, and get the original string. For more details please see the documentation at https://godoc.org/github.com/Masterminds/semver.

Sorting Semantic Versions

A set of versions can be sorted using the `sort` package from the standard library. For example,

    raw := []string{"1.2.3", "1.0", "1.3", "2", "0.4.2",}
    vs := make([]*semver.Version, len(raw))
	for i, r := range raw {
		v, err := semver.NewVersion(r)
		if err != nil {
			t.Errorf("Error parsing version: %s", err)
		}

		vs[i] = v
	}

	sort.Sort(semver.Collection(vs))

Checking Version Constraints

Checking a version against version constraints is one of the most featureful parts of the package.

c, err := semver.NewConstraint(">= 1.2.3")
if err != nil {
    // Handle constraint not being parseable.
}

v, _ := semver.NewVersion("1.3")
if err != nil {
    // Handle version not being parseable.
}
// Check if the version meets the constraints. The a variable will be true.
a := c.Check(v)

Basic Comparisons

There are two elements to the comparisons. First, a comparison string is a list of comma separated and comparisons. These are then separated by || separated or comparisons. For example, `">= 1.2, < 3.0.0 || >= 4.2.3"` is looking for a comparison that's greater than or equal to 1.2 and less than 3.0.0 or is greater than or equal to 4.2.3.

The basic comparisons are:

* `=`: equal (aliased to no operator)
* `!=`: not equal
* `>`: greater than
* `<`: less than
* `>=`: greater than or equal to
* `<=`: less than or equal to

Hyphen Range Comparisons

There are multiple methods to handle ranges and the first is hyphens ranges. These look like:

* `1.2 - 1.4.5` which is equivalent to `>= 1.2, <= 1.4.5`
* `2.3.4 - 4.5` which is equivalent to `>= 2.3.4, <= 4.5`

Wildcards In Comparisons

The `x`, `X`, and `*` characters can be used as a wildcard character. This works for all comparison operators. When used on the `=` operator it falls back to the pack level comparison (see tilde below). For example,

* `1.2.x` is equivalent to `>= 1.2.0, < 1.3.0`
* `>= 1.2.x` is equivalent to `>= 1.2.0`
* `<= 2.x` is equivalent to `<= 3`
* `*` is equivalent to `>= 0.0.0`

Tilde Range Comparisons (Patch)

The tilde (`~`) comparison operator is for patch level ranges when a minor version is specified and major level changes when the minor number is missing. For example,

* `~1.2.3` is equivalent to `>= 1.2.3, < 1.3.0`
* `~1` is equivalent to `>= 1, < 2`
* `~2.3` is equivalent to `>= 2.3, < 2.4`
* `~1.2.x` is equivalent to `>= 1.2.0, < 1.3.0`
* `~1.x` is equivalent to `>= 1, < 2`

Caret Range Comparisons (Major)

The caret (`^`) comparison operator is for major level changes. This is useful when comparisons of API versions as a major change is API breaking. For example,

* `^1.2.3` is equivalent to `>= 1.2.3, < 2.0.0`
* `^1.2.x` is equivalent to `>= 1.2.0, < 2.0.0`
* `^2.3` is equivalent to `>= 2.3, < 3`
* `^2.x` is equivalent to `>= 2.0.0, < 3`

Imported by 191 package(s)

  1. github.com/2opremio/helm/action
  2. github.com/2opremio/helm/chart
  3. github.com/Azure/draft/pkg/draft/pack/repo/installer
  4. github.com/Azure/draft/pkg/plugin/installer
  5. github.com/Barberrrry/glide/cmd
  6. github.com/FGrosse/glide/action
  7. github.com/FGrosse/glide/cache
  8. github.com/FGrosse/glide/repo
  9. github.com/Masterminds/glide-report/rules
  10. github.com/Masterminds/glide/action
  11. github.com/Masterminds/glide/cache
  12. github.com/Masterminds/glide/repo
  13. github.com/PolymerLabs/polygit2/repo
  14. github.com/Skarlso/glide/action
  15. github.com/Skarlso/glide/cache
  16. github.com/Skarlso/glide/repo
  17. github.com/Songmu/gitmock
  18. github.com/Songmu/gitsemvers
  19. github.com/Songmu/maltmill
  20. github.com/Southclaws/sampctl
  21. github.com/Southclaws/sampctl/rook
  22. github.com/Southclaws/sampctl/versioning
  23. github.com/TheHippo/glide/cmd
  24. github.com/UNINETT/appstore/pkg/chart
  25. github.com/akutz/glide/action
  26. github.com/akutz/glide/cache
  27. github.com/akutz/glide/cmd
  28. github.com/akutz/glide/repo
  29. github.com/albrow/glide/action
  30. github.com/albrow/glide/cache
  31. github.com/albrow/glide/repo
  32. github.com/alde/glide/repo
  33. github.com/andrewzeneski/glide/cmd
  34. github.com/autonomy/conform/pkg/metadata
  35. github.com/autonomy/conform/pkg/utilities
  36. github.com/bacongobbler/glide/repo
  37. github.com/binhq/binbrew/pkg
  38. github.com/binhq/binbrew/pkg/github
  39. github.com/bryanpaluch/glide/repo
  40. github.com/cafebazaar/helm/action
  41. github.com/cafebazaar/helm/chart
  42. github.com/caseyhadden/glide/cmd
  43. github.com/ckeyer/commons/version
  44. github.com/cloudfoundry/libbuildpack
  45. github.com/cloudfoundry/libbuildpack/packager
  46. github.com/cpg1111/glide/cmd
  47. github.com/creasty/rid/docker
  48. github.com/daniel-garcia/glide/repo
  49. github.com/danielqsj/helm/pkg/lint/rules
  50. github.com/deis/helm/action
  51. github.com/deis/helm/chart
  52. github.com/dmitris/glide/cache
  53. github.com/dmitris/glide/repo
  54. github.com/elopio/helm/pkg/lint/rules
  55. github.com/favadi/glide/cmd
  56. github.com/fibonacci1729/glide/repo
  57. github.com/foxish/helm/pkg/lint/rules
  58. github.com/foxish/helm/pkg/repo
  59. github.com/foxish/helm/pkg/version
  60. github.com/franciscocpg/glide/action
  61. github.com/franciscocpg/glide/cache
  62. github.com/franciscocpg/glide/repo
  63. github.com/fschl/glide/repo
  64. github.com/gabrtv/helm/pkg/lint/rules
  65. github.com/gardener/gardener/pkg/apis/garden/validation
  66. github.com/gardener/gardener/pkg/operation/shoot
  67. github.com/gardener/gardener/pkg/utils
  68. github.com/garywu125/glide/repo
  69. github.com/gdm85/glide/repo
  70. github.com/geramirez/glide/cmd
  71. github.com/getcarina/carina/cmd
  72. github.com/go-task/task
  73. github.com/go-task/task/internal/taskfile/version
  74. github.com/golang/dep/gps
  75. github.com/gravitational/helm/pkg/lint/rules
  76. github.com/hectorj/glide/cmd
  77. github.com/helm/helm-classic/action
  78. github.com/helm/helm-classic/chart
  79. github.com/helm/helm/action
  80. github.com/helm/helm/chart
  81. github.com/helm/monocular/src/api/chartpackagesort
  82. github.com/helm/monocular/src/api/data/helpers
  83. github.com/howtowhale/dvm/dvm-helper
  84. github.com/howtowhale/dvm/dvm-helper/dockerversion
  85. github.com/hyperdriven/hyperdrive
  86. github.com/imikushin/glide/cmd
  87. github.com/itscaro/glide/cmd
  88. github.com/jackfrancis/helm/cmd/helm/resolver
  89. github.com/jackfrancis/helm/pkg/lint/rules
  90. github.com/jackfrancis/helm/pkg/version
  91. github.com/jackfrancis/monocular/src/api/data/helpers
  92. github.com/jrick/glide/cmd
  93. github.com/karfield/glide/repo
  94. github.com/kelcecil/glide/action
  95. github.com/kelcecil/glide/cache
  96. github.com/kelcecil/glide/repo
  97. github.com/klaidliadon/glide/repo
  98. github.com/kngu9/glide/repo
  99. github.com/kshlm/glide/cmd
  100. github.com/kubepack/dep/gps
  101. github.com/kubernetes-helm/monocular/src/api/chartpackagesort
  102. github.com/kubernetes-helm/monocular/src/api/data/helpers
  103. github.com/kubernetes-incubator/kube-aws/core/controlplane/config
  104. github.com/kubernetes/helm/pkg/downloader
  105. github.com/kubernetes/helm/pkg/lint/rules
  106. github.com/kubernetes/helm/pkg/resolver
  107. github.com/lamielle/glide/cmd
  108. github.com/lanej/helm/helm/model
  109. github.com/masterminds/glide-report/rules
  110. github.com/masterminds/glide/action
  111. github.com/masterminds/glide/cache
  112. github.com/masterminds/glide/repo
  113. github.com/mattfarina/go-test
  114. github.com/mfycheng/glide/action
  115. github.com/mfycheng/glide/cache
  116. github.com/mfycheng/glide/repo
  117. github.com/mgutz/glide/action
  118. github.com/mgutz/glide/cache
  119. github.com/mgutz/glide/repo
  120. github.com/mh-cbon/changelog/changelog
  121. github.com/mh-cbon/changelog/tpls
  122. github.com/mh-cbon/gh-api-cli/dl
  123. github.com/mh-cbon/gh-api-cli/gh
  124. github.com/mh-cbon/glide/repo
  125. github.com/mh-cbon/go-bin-rpm/rpm
  126. github.com/mh-cbon/go-msi
  127. github.com/mh-cbon/go-msi/manifest
  128. github.com/mh-cbon/go-repo-utils/repoutils
  129. github.com/michelleN/helm/action
  130. github.com/michelleN/helm/chart
  131. github.com/miolini/glide/cmd
  132. github.com/mroote/factorio-server-manager/src
  133. github.com/mstrzele/minikube-nfs
  134. github.com/mstrzele/shipsbell
  135. github.com/myENA/glide/action
  136. github.com/myENA/glide/cache
  137. github.com/myENA/glide/repo
  138. github.com/n0needt0/glide/repo
  139. github.com/nourish/glide/repo
  140. github.com/paulmach/glide/cmd
  141. github.com/percona/qan-agent/mysql
  142. github.com/percona/qan-agent/test/version
  143. github.com/polaris1119/glide/repo
  144. github.com/rai-project/dlframework
  145. github.com/rai-project/dlframework/framework
  146. github.com/rai-project/dlframework/http
  147. github.com/rai-project/dlframework/registryquery
  148. github.com/ryanfowler/glide/action
  149. github.com/ryanfowler/glide/cache
  150. github.com/ryanfowler/glide/repo
  151. github.com/s-urbaniak/glide/repo
  152. github.com/sdboyer/gps
  153. github.com/sdboyer/vsolver
  154. github.com/semantic-release/go-semantic-release
  155. github.com/sgoings/helm/pkg/lint/rules
  156. github.com/sgotti/glide/repo
  157. github.com/shyiko/jabba/semver
  158. github.com/sidkshatriya/dontbug/engine
  159. github.com/skarlso/glide/action
  160. github.com/skarlso/glide/cache
  161. github.com/skarlso/glide/repo
  162. github.com/smartrecruiters/docker-bakery/bakery/service
  163. github.com/smothiki/helm/action
  164. github.com/smothiki/helm/chart
  165. github.com/socialplanner/instahelper/app/update
  166. github.com/stapelberg/helm/pkg/lint/rules
  167. github.com/szuecs/glide-report/rules
  168. github.com/thockin/glide/repo
  169. github.com/tudyzhou/glide/repo
  170. github.com/vburenin/glide/action
  171. github.com/vburenin/glide/cache
  172. github.com/vburenin/glide/repo
  173. github.com/yanyiwu/glide/repo
  174. github.com/yazgazan/backomp
  175. github.com/yeka/glide/repo
  176. github.com/zellyn/vsolver
  177. github.com/zjx20/glide/action
  178. github.com/zjx20/glide/repo
  179. gopkg.in/Masterminds/glide.v0/action
  180. gopkg.in/Masterminds/glide.v0/cache
  181. gopkg.in/Masterminds/glide.v0/cmd
  182. gopkg.in/Masterminds/glide.v0/repo
  183. gopkg.in/masterminds/glide.v0/action
  184. gopkg.in/masterminds/glide.v0/cache
  185. gopkg.in/masterminds/glide.v0/repo
  186. k8s.io/helm/cmd/helm/downloader
  187. k8s.io/helm/cmd/helm/resolver
  188. k8s.io/helm/cmd/helm/search
  189. k8s.io/helm/pkg/lint/rules
  190. k8s.io/helm/pkg/repo
  191. k8s.io/helm/pkg/version

Imported only in test by 4 package(s)

  1. github.com/johnt337/semver
  2. github.com/masterminds/semver
  3. github.com/mh-cbon/semver
  4. github.com/percona/percona-toolkit/src/go/mongolib/explain