mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
Update version.go
Optimize duplicate code
This commit is contained in:
parent
bcbdfcb99b
commit
3f1174a519
@ -25,31 +25,25 @@ func Full() string {
|
|||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
func Proto(v string) int64 {
|
func getSubVersion(v string, position int) int64 {
|
||||||
arr := strings.Split(v, ".")
|
arr := strings.Split(v, ".")
|
||||||
if len(arr) < 3 {
|
if len(arr) < 3 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
res, _ := strconv.ParseInt(arr[0], 10, 64)
|
res, _ := strconv.ParseInt(arr[position], 10, 64)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Proto(v string) int64 {
|
||||||
|
return getSubVersion(v, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func Major(v string) int64 {
|
func Major(v string) int64 {
|
||||||
arr := strings.Split(v, ".")
|
return getSubVersion(v, 1)
|
||||||
if len(arr) < 3 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
res, _ := strconv.ParseInt(arr[1], 10, 64)
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Minor(v string) int64 {
|
func Minor(v string) int64 {
|
||||||
arr := strings.Split(v, ".")
|
return getSubVersion(v, 2)
|
||||||
if len(arr) < 3 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
res, _ := strconv.ParseInt(arr[2], 10, 64)
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add every case there if server will not accept client's protocol and return false
|
// add every case there if server will not accept client's protocol and return false
|
||||||
|
Loading…
Reference in New Issue
Block a user