How to compare two version number strings in golang

前端 未结 10 746
别跟我提以往
别跟我提以往 2020-12-30 02:06

I have two strings (they are actually version numbers and they could be any version numbers)

a := \"1.05.00.0156\"  
b := \"1.0.221.9289\"

10条回答
  •  执念已碎
    2020-12-30 02:24

    go-semver is a semantic versioning library for Go. It lets you parse and compare two semantic version strings.

    Example:

    vA := semver.New("1.2.3")
    vB := semver.New("3.2.1")
    
    fmt.Printf("%s < %s == %t\n", vA, vB, vA.LessThan(*vB))
    

    Output:

    1.2.3 < 3.2.1 == true

提交回复
热议问题