version

package module
v0.0.0-...-0519a69 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 2 Imported by: 0

README

go-pacman-version

A lightweight, pure Go library for parsing and comparing Arch Linux (Pacman) package versions.

This library implements the exact version comparison logic used by libalpm (the core library of Pacman), ensuring that your Go applications resolve version ordering exactly as Pacman does.

Features

  • Pure Go: No CGO or external dependencies.
  • Spec Compliant: Implements the rpmvercmp algorithm used by Arch Linux.
  • Robust: Handles complex version strings including Epochs (1:1.0), versions (1.0), and releases (-1).
  • Permissive: Like Pacman, it handles malformed strings gracefully without panicking.

Used by

Used by Copacetic

Installation

go get [github.com/parthivsaikia/go-pacman-version](https://github.com/parthivsaikia/go-pacman-version)

Usage

package main

import (
    "fmt"
    pacman "github.com/parthivsaikia/go-pacman-version"
)

func main() {
    v1 := "1.0.0-1"
    v2 := "1.0.0-2"

    // Check if a version string is valid (not empty)
    if pacman.IsValid(v1) {
        fmt.Println("Version is valid")
    }

    // Compare versions
    if pacman.LessThan(v1, v2) {
        fmt.Printf("%s is older than %s\n", v1, v2)
    }

    // Direct comparison (returns -1, 0, or 1)
    // -1 = v1 < v2
    //  0 = v1 == v2
    //  1 = v1 > v2
    cmp := pacman.Compare("1:2.0-1", "2.0-1")
    fmt.Println(cmp) // Output: 1 (because Epoch 1 > Epoch 0)
}

Version Format

The library expects strings in the standard Arch Linux format:

[epoch:]version[-release]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(v1, v2 string) int

func IsValid

func IsValid(v string) bool

func LessThan

func LessThan(v1, v2 string) bool

func MoreThan

func MoreThan(v1, v2 string) bool

Types

This section is empty.

Jump to

Keyboard shortcuts

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