Skip to content

SuffixWeight

类型 · 根包

go
type SuffixWeight int

📖 说明

SuffixWeight 表示版本后缀的语义权重

SuffixWeight 用于在版本比较时为不同类型的后缀分配语义化的权重值, 使得预发布版本的排序符合实际发布顺序,而非简单的字典序。

完整权重表(从低到高)

权重值常量匹配后缀含义
0SuffixWeightUnknown(未匹配)未知后缀
50SuffixWeightDevdevdev.1开发版
60SuffixWeightSnapshotsnapshotSNAPSHOT快照版(Maven 生态)
70SuffixWeightNightlynightly夜间构建版
100SuffixWeightAlphaalphaa1Alpha 版
200SuffixWeightBetabetab2Beta 版
300SuffixWeightMilestonemilestonem1里程碑版
400SuffixWeightRCrc1RC2候选发布版
410SuffixWeightPrepre1预发布版
420SuffixWeightCRcr1候选发布版(CR 变体)
500SuffixWeightFinal / Release / GAfinalreleasega正式版(三个常量同值)
600SuffixWeightSPsp1服务包(高于正式版)
700SuffixWeightPatchpatch1补丁版(高于正式版)
800SuffixWeightPostpost1Post 发布版(PEP 440,高于正式版)

反直觉:sp/patch/post 高于正式版

注意 sp(600)patch(700)post(800) 的权重大于正式版 final/release/ga(500)。这是因为在语义上,1.0.0-sp1 是在 1.0.0 正式版之后发布的服务包,1.0.0-post1 是 PEP 440 中正式版之后的修订。因此 1.0.0-post1 > 1.0.0 > 1.0.0-rc1

源码 doc 注释只列了 dev/snapshot < alpha < beta < milestone < rc < 正式版,遗漏了 sp/patch/post 三档,以本表为准

go
weight := GetSuffixWeight("-alpha1")
fmt.Println(weight) // 100

fmt.Println(GetSuffixWeight("-post1") > GetSuffixWeight("")) // true,post 高于正式版

源码位置

定义于 suffix_weight.go

基于 MIT 协议发布