module

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package module provides functionalities for working with module path and versions.

Index

Constants

View Source
const (
	// ErrInvalidVersion indicates that the version is invalid.
	ErrInvalidVersion = xerrors.Error("invalid version")
)

Variables

View Source
var (
	// PathVersionRegExp matches a module version string.
	PathVersionRegExp = regexp.MustCompile(`^([a-zA-Z0-9]+([a-zA-Z0-9_/]+)?)?v\d+\.\d+\.\d+$`)
	// VersionRegExp matches a version string.
	VersionRegExp = regexp.MustCompile(`^v?(\d+)\.(\d+)\.(\d+)$`)
	// MajorVersionRegExp matches a major version string.
	MajorVersionRegExp = regexp.MustCompile(`^v?(\d+)$`)
)

Functions

func FindVersions

func FindVersions(dir string) ([]string, error)

FindVersions returns the module versions in the given path.

func PathVersion

func PathVersion(s string) (Path, Version)

PathVersion returns the path and version from a module version string.

func PathWithVersion added in v0.4.0

func PathWithVersion[P ~string](path P, v Version) string

PathWithVersion returns the path with the version.

func PathWithoutVersion added in v0.4.0

func PathWithoutVersion[P ~string](path P) string

PathWithoutVersion returns the path without the version.

Types

type Finder

type Finder interface {
	Find(loc, ref string) (map[Path]Version, error)
}

Finder finds modules.

type Path

type Path string

Path is the path to the module.

func (Path) IsRoot

func (p Path) IsRoot() bool

IsRoot returns true if the path is the root path.

type Version

type Version struct {
	Major int
	Minor int
	Patch int
}

Version is the version of the module.

func NewVersion

func NewVersion(major, minor, patch int) Version

NewVersion returns a new version.

func NewVersionFromString

func NewVersionFromString(s string) Version

NewVersionFromString returns a new version from a string.

func (Version) LessThan

func (v Version) LessThan(v2 Version) bool

LessThan returns true if the left version is less than the right version.

func (Version) String

func (v Version) String() string

String returns the string representation of the version.

Jump to

Keyboard shortcuts

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