version

package module
v0.0.0-...-19e87b7 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: MIT Imports: 8 Imported by: 0

README

go-pacman-version

Test Go Report Card MIT License

A Go library for parsing pacman package versions

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

The implementation is based on vercmp(8), this implementation

OS: Arch Linux

Installation and Usage

Installation can be done with a normal go get:

$ go get github.com/MaineK00n/go-pacman-version

Version Parsing and Comparison

import version "github.com/MaineK00n/go-pacman-version"

v1, err := version.NewVersion("5.1.004-1")
v2, err := version.NewVersion("5.1.008-1")

// Comparison example. You can use GreaterThan and Equal as well.
if v1.LessThan(v2) {
    fmt.Printf("%s is less than %s", v1, v2)
}

Version Sorting

raw := []string{"5.1.008-1", "5.1.0-2", "5.1.004-1", "5.1.0-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/MaineK00n/go-pacman-version to github.com/you/repo
  2. get original code: go get github.com/MaineK00n/go-pacman-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

MaineK00n(@MaineK00n)

Documentation

Index

Constants

View Source
const (
	LESS    = -1
	EQUAL   = 0
	GREATER = 1
)

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. (https://archlinux.org/pacman/vercmp.8.html)

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. The result will be 0 if v1==v2, -1 if v1 < v2, and +1 if v1 > v2.

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) String

func (v1 Version) String() string

String returns the full version string

Jump to

Keyboard shortcuts

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