阅读(2573) (9)

GoFrame gstr-版本比较

2022-04-11 15:15:53 更新

CompareVersion

  • 说明:​CompareVersion​将​a​和​b​作为标准​GNU​版本进行比较。  
  • 格式:

CompareVersion(a, b string) int

  • 示例:

func ExampleCompareVersion() {
	fmt.Println(gstr.CompareVersion("v2.11.9", "v2.10.8"))
	fmt.Println(gstr.CompareVersion("1.10.8", "1.19.7"))
	fmt.Println(gstr.CompareVersion("2.8.beta", "2.8"))

	// Output:
	// 1
	// -1
	// 0
}

CompareVersionGo

  • 说明:​CompareVersionGo​将​a​和​b​作为标准的​Golang​版本进行比较。  
  • 格式:

CompareVersionGo(a, b string) int

  • 示例:

func ExampleCompareVersionGo() {
	fmt.Println(gstr.CompareVersionGo("v2.11.9", "v2.10.8"))
	fmt.Println(gstr.CompareVersionGo("v4.20.1", "v4.20.1+incompatible"))
	fmt.Println(gstr.CompareVersionGo(
		"v0.0.2-20180626092158-b2ccc119800e",
		"v1.0.1-20190626092158-b2ccc519800e",
	))

	// Output:
	// 1
	// 1
	// -1
}