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 131 package(s)

  1. github.com/2opremio/helm/action
  2. github.com/2opremio/helm/chart
  3. github.com/Barberrrry/glide/cmd
  4. github.com/FGrosse/glide/action
  5. github.com/FGrosse/glide/cache
  6. github.com/FGrosse/glide/repo
  7. github.com/Masterminds/glide-report/rules
  8. github.com/Masterminds/glide/action
  9. github.com/Masterminds/glide/cache
  10. github.com/Masterminds/glide/repo
  11. github.com/PolymerLabs/polygit2/repo
  12. github.com/Skarlso/glide/action
  13. github.com/Skarlso/glide/cache
  14. github.com/Skarlso/glide/repo
  15. github.com/Songmu/gitmock
  16. github.com/Songmu/gitsemvers
  17. github.com/TheHippo/glide/cmd
  18. github.com/akutz/glide/action
  19. github.com/akutz/glide/cache
  20. github.com/akutz/glide/cmd
  21. github.com/akutz/glide/repo
  22. github.com/albrow/glide/action
  23. github.com/albrow/glide/cache
  24. github.com/albrow/glide/repo
  25. github.com/alde/glide/repo
  26. github.com/andrewzeneski/glide/cmd
  27. github.com/bacongobbler/glide/repo
  28. github.com/bryanpaluch/glide/repo
  29. github.com/cafebazaar/helm/action
  30. github.com/cafebazaar/helm/chart
  31. github.com/caseyhadden/glide/cmd
  32. github.com/cpg1111/glide/cmd
  33. github.com/daniel-garcia/glide/repo
  34. github.com/deis/helm/action
  35. github.com/deis/helm/chart
  36. github.com/dmitris/glide/repo
  37. github.com/favadi/glide/cmd
  38. github.com/fibonacci1729/glide/repo
  39. github.com/foxish/helm/pkg/repo
  40. github.com/foxish/helm/pkg/version
  41. github.com/franciscocpg/glide/action
  42. github.com/franciscocpg/glide/cache
  43. github.com/franciscocpg/glide/repo
  44. github.com/fschl/glide/repo
  45. github.com/gabrtv/helm/pkg/lint/rules
  46. github.com/garywu125/glide/repo
  47. github.com/gdm85/glide/repo
  48. github.com/geramirez/glide/cmd
  49. github.com/gravitational/helm/pkg/lint/rules
  50. github.com/hectorj/glide/cmd
  51. github.com/helm/helm-classic/action
  52. github.com/helm/helm-classic/chart
  53. github.com/helm/helm/action
  54. github.com/helm/helm/chart
  55. github.com/imikushin/glide/cmd
  56. github.com/itscaro/glide/cmd
  57. github.com/jackfrancis/helm/cmd/helm/resolver
  58. github.com/jackfrancis/helm/pkg/lint/rules
  59. github.com/jackfrancis/helm/pkg/version
  60. github.com/jrick/glide/cmd
  61. github.com/karfield/glide/repo
  62. github.com/kelcecil/glide/action
  63. github.com/kelcecil/glide/cache
  64. github.com/kelcecil/glide/repo
  65. github.com/klaidliadon/glide/repo
  66. github.com/kngu9/glide/repo
  67. github.com/kshlm/glide/cmd
  68. github.com/kubernetes/helm/pkg/lint/rules
  69. github.com/lamielle/glide/cmd
  70. github.com/lanej/helm/helm/model
  71. github.com/masterminds/glide-report/rules
  72. github.com/masterminds/glide/action
  73. github.com/masterminds/glide/cache
  74. github.com/masterminds/glide/repo
  75. github.com/mfycheng/glide/action
  76. github.com/mfycheng/glide/cache
  77. github.com/mfycheng/glide/repo
  78. github.com/mgutz/glide/action
  79. github.com/mgutz/glide/cache
  80. github.com/mgutz/glide/repo
  81. github.com/mh-cbon/changelog/changelog
  82. github.com/mh-cbon/changelog/tpls
  83. github.com/mh-cbon/gh-api-cli/dl
  84. github.com/mh-cbon/gh-api-cli/gh
  85. github.com/mh-cbon/glide/repo
  86. github.com/mh-cbon/go-repo-utils/repoutils
  87. github.com/michelleN/helm/action
  88. github.com/michelleN/helm/chart
  89. github.com/miolini/glide/cmd
  90. github.com/n0needt0/glide/repo
  91. github.com/nourish/glide/repo
  92. github.com/paulmach/glide/cmd
  93. github.com/polaris1119/glide/repo
  94. github.com/ryanfowler/glide/action
  95. github.com/ryanfowler/glide/cache
  96. github.com/ryanfowler/glide/repo
  97. github.com/s-urbaniak/glide/repo
  98. github.com/sdboyer/gps
  99. github.com/sdboyer/vsolver
  100. github.com/sgoings/helm/pkg/lint/rules
  101. github.com/sgotti/glide/repo
  102. github.com/sidkshatriya/dontbug/engine
  103. github.com/skarlso/glide/action
  104. github.com/skarlso/glide/cache
  105. github.com/skarlso/glide/repo
  106. github.com/smothiki/helm/action
  107. github.com/smothiki/helm/chart
  108. github.com/stapelberg/helm/pkg/lint/rules
  109. github.com/szuecs/glide-report/rules
  110. github.com/thockin/glide/repo
  111. github.com/tudyzhou/glide/repo
  112. github.com/vburenin/glide/action
  113. github.com/vburenin/glide/cache
  114. github.com/vburenin/glide/repo
  115. github.com/yanyiwu/glide/repo
  116. github.com/zellyn/vsolver
  117. github.com/zjx20/glide/action
  118. github.com/zjx20/glide/repo
  119. gopkg.in/Masterminds/glide.v0/action
  120. gopkg.in/Masterminds/glide.v0/cache
  121. gopkg.in/Masterminds/glide.v0/cmd
  122. gopkg.in/Masterminds/glide.v0/repo
  123. gopkg.in/masterminds/glide.v0/action
  124. gopkg.in/masterminds/glide.v0/cache
  125. gopkg.in/masterminds/glide.v0/repo
  126. k8s.io/helm/cmd/helm/downloader
  127. k8s.io/helm/cmd/helm/resolver
  128. k8s.io/helm/cmd/helm/search
  129. k8s.io/helm/pkg/lint/rules
  130. k8s.io/helm/pkg/repo
  131. k8s.io/helm/pkg/version

Imported only in test by 2 package(s)

  1. github.com/johnt337/semver
  2. github.com/masterminds/semver