version

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package version 提供构建期嵌入的版本元数据和 SemVer 解析、比较与渠道判定。

Version 由发布构建通过 -ldflags -X 覆盖。

包的组成:Version 与 Info 是构建元数据,Semantic 与 Parse 处理已校验 版本,Compare、Validate 与 Channel 提供比较和分类。

Index

Constants

This section is empty.

Variables

View Source
var Version = "dev"

Version 由发布构建通过 -ldflags -X 覆盖;本地开发构建保留可识别的默认值。

Functions

func Channel

func Channel(version string) string

Channel 将已通过 Validate 的 version 分类为 stable 或 prerelease。

func Compare

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

Compare 按 SemVer 2.0 precedence 比较两个 version: 返回负数、零或正数分别表示 a 低于、等于或高于 b。build metadata 不参与 precedence。 数字 identifier 按规范十进制字符串比较(先长度后字典序),因此任意长度都不会溢出。

func Validate

func Validate(version string) error

Validate 要求 version 是不带前导 v 的 semantic version。

Types

type Info

type Info struct {
	Version string `json:"version"`
}

Info 提供 CLI 可安全展示的构建元数据。

func Current

func Current() Info

Current 返回当前二进制嵌入的构建元数据。

func (Info) IsDevelopment

func (info Info) IsDevelopment() bool

IsDevelopment 识别没有发布渠道的开发构建。

type Semantic

type Semantic struct {
	// contains filtered or unexported fields
}

Semantic 保存已校验的版本及其 precedence 字段;通过 Parse 构造。

func Parse

func Parse(text string) (Semantic, error)

Parse 校验并解析不带 v 前缀的 SemVer,保留原始 build metadata。

func (Semantic) Compare

func (v Semantic) Compare(other Semantic) int

Compare 比较已经通过 Parse 校验的版本,忽略 build metadata。

func (Semantic) IsPrerelease

func (v Semantic) IsPrerelease() bool

IsPrerelease 报告该版本是否带有 prerelease 标识符。

func (Semantic) String

func (v Semantic) String() string

String 返回不带 v 前缀的 canonical 版本。

Jump to

Keyboard shortcuts

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