您当前的位置: 首页 >  golang

彭世瑜

暂无认证

  • 4浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Golang:go-version一个对语义化版本进行解析、比较的库

彭世瑜 发布时间:2022-09-27 09:48:52 ,浏览量:4

go-version is a library for parsing versions and version constraints, and verifying versions against a set of constraints. go-version can sort a collection of versions properly, handles prerelease/beta versions, can increment versions, etc.

译文:go-version是一个库,用于解析版本和版本约束,并根据一组约束验证版本。go-version 可以对版本集合进行正确排序,处理预发布/测试版,可以增加版本,等等。

文档

  • github https://github.com/hashicorp/go-version

  • pkg.go https://pkg.go.dev/github.com/hashicorp/go-version

  • 语义化版本 2.0.0 https://semver.org/lang/zh-CN/

安装

go get github.com/hashicorp/go-version

示例

package main

import (
    "fmt"

    "github.com/hashicorp/go-version"
)

func main() {
    v1, _ := version.NewVersion("1.2")

    v2, _ := version.NewVersion("2.1")

    if v1.LessThan(v2) {
        fmt.Printf("%s is less than %s", v1, v2)
    }
    // 1.2.0 is less than 2.1.0
}

参考 「Go工具箱」一个对语义化版本进行解析、比较的库:go-version

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.2949s