version

package module
v0.0.0-...-3ed183d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 7 Imported by: 92

README

go-deb-version

Build Status Coverage Status Go Report Card MIT License

A Go library for parsing package versions

go-deb-version is a library for parsing and comparing versions

Versions used with go-deb-version must follow deb-version (ex. 2:6.0-9ubuntu1)
The implementation is based on Debian Policy Manual

OS: Debian, Ubnutu

Installation and Usage

Installation can be done with a normal go get:

$ go get github.com/knqyf263/go-deb-version

Version Parsing and Comparison

import "github.com/knqyf263/go-deb-version"

v1, err := version.NewVersion("2:6.0-9")
v2, err := version.NewVersion("2:6.0-9ubuntu1")

// Comparison example. There is also GreaterThan, Equal.
if v1.LessThan(v2) {
    fmt.Printf("%s is less than %s", v1, v2)
}

Version Sorting

raw := []string{"7.4.052-1ubuntu3.1", "7.4.052-1ubuntu3", "7.1-022+1ubuntu1", "7.1.291-1", "7.3.000+hg~ee53a39d5896-1"}
vs := make([]version.Version, len(raw))
for i, r := range raw {
	v, _ := version.NewVersion(r)
	vs[i] = v
}

sort.Slice(vs, func(i, j int) bool {
	return vs[i].LessThan(vs[j])
})

Contribute

  1. fork a repository: github.com/knqyf263/go-deb-version to github.com/you/repo
  2. get original code: go get github.com/knqyf263/go-deb-version
  3. work on original code
  4. add remote to your repo: git remote add myfork https://github.com/you/repo.git
  5. push your changes: git push myfork
  6. create a new Pull Request

License

MIT

Author

Teppei Fukuda

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Valid

func Valid(ver string) bool

Valid validates the version

Types

type Version

type Version struct {
	// contains filtered or unexported fields
}

Version represents a package version (http://man.he.net/man5/deb-version).

func NewVersion

func NewVersion(ver string) (version Version, err error)

NewVersion returns a parsed version

func (*Version) Compare

func (v1 *Version) Compare(v2 Version) int

Compare returns an integer comparing two version according to deb-version. The result will be 0 if v1==v2, -1 if v1 < v2, and +1 if v1 > v2.

func (*Version) Epoch

func (v1 *Version) Epoch() int

func (*Version) Equal

func (v1 *Version) Equal(v2 Version) bool

Equal returns whether this version is equal with another version.

func (*Version) GreaterThan

func (v1 *Version) GreaterThan(v2 Version) bool

GreaterThan returns whether this version is greater than another version.

func (*Version) LessThan

func (v1 *Version) LessThan(v2 Version) bool

LessThan returns whether this version is less than another version.

func (*Version) Revision

func (v1 *Version) Revision() string

func (*Version) String

func (v1 *Version) String() string

String returns the full version string

func (*Version) Version

func (v1 *Version) Version() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL