dpkgcomp

package module
v0.0.0-...-46af647 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2015 License: Apache-2.0 Imports: 4 Imported by: 0

README

DpkgComp Coverage GoDoc

About

This Go library compares Debian-like package version numbers. For instance, it can tell that version 1:1.25-4 is lower than 1:1.25-8.

The implementation is based on http://man.he.net/man5/deb-version and on https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version. The algorithm is inspired from dpkg-1.17.25 (lib/version.c and lib/parsehelp.c).

Installing

Installing this library is easy-peasy, as usual.

go get github.com/quentin-m/dpkgcomp

You could also run tests

go test github.com/quentin-m/dpkgcomp

Usage

Will you be able to guess the ouput ?

package main

import (
	"log"

	"github.com/quentin-m/dpkgcomp"
)
func main() {
	// Define our version numbers
	v1 := "0:1.18.36-a"
	v2 := "1.18.36"

    // Compare our versions
	cmp, err := dpkgcomp.Compare(v1, v2)
	if err != nil {
		log.Fatalln(err)
	}
	if cmp == 0 {
		log.Println(v1, "is equal to", v2)
	} else if cmp == 1 {
		log.Println(v1, "is higher than", v2)
	} else {
		log.Println(v1, "is lower than", v2)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b string) (int, error)

Compare function compares two Debian-like package version

The implementation is based on http://man.he.net/man5/deb-version on https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version

It uses the dpkg-1.17.25's algorithm (lib/version.c)

func CompareV

func CompareV(a, b Version) int

CompareV function compares two Debian-like package version

The implementation is based on http://man.he.net/man5/deb-version on https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version

It uses the dpkg-1.17.25's algorithm (lib/version.c)

Types

type Version

type Version struct {
	Epoch           int
	UpstreamVersion string
	DebianRevision  string
}

Version represents a Debian-like package version

func StringToVersion

func StringToVersion(str string) (Version, error)

StringToVersion function parses a string into a Version struct which can be compared

The implementation is based on http://man.he.net/man5/deb-version on https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version

It uses the dpkg-1.17.25's algorithm (lib/parsehelp.c)

Jump to

Keyboard shortcuts

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