You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.1 KiB

  1. go-version [![Build Status](https://travis-ci.org/mcuadros/go-version.png?branch=master)](https://travis-ci.org/mcuadros/go-version) [![GoDoc](https://godoc.org/github.com/mcuadros/go-version?status.png)](http://godoc.org/github.com/mcuadros/go-version)
  2. ==============================
  3. Version normalizer and comparison library for go, heavy based on PHP version_compare function and Version comparsion libs from [Composer](https://github.com/composer/composer) PHP project
  4. Installation
  5. ------------
  6. The recommended way to install go-version
  7. ```
  8. go get github.com/mcuadros/go-version
  9. ```
  10. Examples
  11. --------
  12. How import the package
  13. ```go
  14. import (
  15. "github.com/mcuadros/go-version"
  16. )
  17. ```
  18. `version.Normalize()`: Normalizes a version string to be able to perform comparisons on it
  19. ```go
  20. version.Normalize("10.4.13-b")
  21. //Returns: 10.4.13.0-beta
  22. ```
  23. `version.CompareSimple()`: Compares two normalizated version number strings
  24. ```go
  25. version.CompareSimple("1.2", "1.0.1")
  26. //Returns: 1
  27. version.CompareSimple("1.0rc1", "1.0")
  28. //Returns: -1
  29. ```
  30. `version.Compare()`: Compares two normalizated version number strings, for a particular relationship
  31. ```go
  32. version.Compare("1.0-dev", "1.0", "<")
  33. //Returns: true
  34. version.Compare("1.0rc1", "1.0", ">=")
  35. //Returns: false
  36. version.Compare("2.3.4", "v3.1.2", "<")
  37. //Returns: true
  38. ```
  39. `version.ConstrainGroup.Match()`: Match a given version againts a group of constrains, read about constraint string format at [Composer documentation](http://getcomposer.org/doc/01-basic-usage.md#package-versions)
  40. ```go
  41. c := version.NewConstrainGroupFromString(">2.0,<=3.0")
  42. c.Match("2.5.0beta")
  43. //Returns: true
  44. c := version.NewConstrainGroupFromString("~1.2.3")
  45. c.Match("1.2.3.5")
  46. //Returns: true
  47. ```
  48. `version.Sort()`: Sorts a string slice of version number strings using version.CompareSimple()
  49. ```go
  50. version.Sort([]string{"1.10-dev", "1.0rc1", "1.0", "1.0-dev"})
  51. //Returns []string{"1.0-dev", "1.0rc1", "1.0", "1.10-dev"}
  52. ```
  53. License
  54. -------
  55. MIT, see [LICENSE](LICENSE)
  56. [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mcuadros/go-version/trend.png)](https://bitdeli.com/free "Bitdeli Badge")