Go 문자열 버전 비교

1 개요[ | ]

Go semver 비교

2 hashicorp/go-version[ | ]

package main

import (
	"fmt"
	"github.com/hashicorp/go-version"
)

func main() {
	v1, _ := version.NewVersion("1.2")
	v2, _ := version.NewVersion("1.5+metadata")
	if v1.LessThan(v2) {
		fmt.Println(v1.String() + " < " + v2.String())
	} else {
		fmt.Println(v1.String() + " >= " + v2.String())
	}
}
package main

import (
	"fmt"
	"github.com/hashicorp/go-version"
)

func main() {
	v1, _ := version.NewVersion("1.05.00.0156")
	v2, _ := version.NewVersion("1.0.221.9289")
	if v1.LessThan(v2) {
		fmt.Println(v1.String() + " < " + v2.String())
	} else {
		fmt.Println(v1.String() + " >= " + v2.String())
	}
}

3 Masterminds/semver[ | ]

package main

import (
	"fmt"

	"github.com/Masterminds/semver"
)

func main() {
	v1, _ := semver.NewVersion("1.2.3")
	v2, _ := semver.NewVersion("3.2.1")

	fmt.Println(v1.Compare(v2)) // -1
	fmt.Println(v2.Compare(v1)) // 1
}

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}