debgover

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 9 Imported by: 0

README

Go Reference

debgover

Go library to convert between Go version strings and Debian package version strings, intended to be compatible with the approach used by the Debian Go team when packaging Go modules.

Library API reference documentation

Copyright © 2026 Richard Hansen <[email protected]> and contributors.

Licensed under the MIT/Expat license.

Documentation

Overview

Package debgover provides functions for converting between Go module version strings and Debian package version strings.

The behavior of this package is intended to conform with the Debian Go team's version number documentation and common practices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebianToGo

func DebianToGo(modPath string, v debversion.Version) (module.Version, error)

DebianToGo converts the upstream part of a Debian version to a Go semver-compatible version. The conversion is lossy; the resulting version is only intended to be used to determine whether a particular version of a Go module has already been Debianized. If the Debian version represents a version control (e.g., Git) snapshot, the returned value is a Go pseudo-version.

Rough approach, which is subject to change:

  1. Start processing the version as if it was a semver version string, except:

    * Add a leading "v" prefix.

    * If a "-" (hyphen) is encountered and it is a legal place to start a pre-release component, the "-" instead stops semver processing and that character to the end of the string are set aside for post processing.

    * If a "~" (tilde) is encountered and it is a legal place to start a pre-release component and the following characters don't match a snapshot indicator (e.g., "~git20251028.abcdef0"), the "~" starts a pre-release component (the "~" is replaced with "-" in the output).

    * If a "+" (plus) is encountered and it is a legal place to start a build metadata component and the following characters match a snapshot indicator (e.g., "+git20251028.abcdef0"), the "+" instead stops semver processing and that character to the end of the string are set aside for post-processing.

    * If a character is encountered that is not legal for semver, semver processing stops and that character to the end of the string are set aside for post-processing.

  2. If the processed part is not a valid semver string, an error is returned.

  3. The semver is canonicalized, with any build metadata component preserved.

  4. If the unprocessed remainder starts with a snapshot indicator (e.g., "~git20251028.abcdef0"), the date, revision, and base version are combined to construct a Go pseudo-version.

  5. The remainder is discarded.

func GoToDebian

func GoToDebian(mod module.Version) (debversion.Version, error)

GoToDebian converts a Go version string to a Debian upstream version. Due to differences between the Debian and semver sorting algorithms, it is technically possible but unlikely for two versions to swap order after conversion. For a Go pseudo-version, the version control system is assumed to be Git.

Types

This section is empty.

Jump to

Keyboard shortcuts

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