1
0

version.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2016 fatedier, fatedier@gmail.com
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package version
  15. import (
  16. "strconv"
  17. "strings"
  18. )
  19. var version string = "0.16.0"
  20. func Full() string {
  21. return version
  22. }
  23. func getSubVersion(v string, position int) int64 {
  24. arr := strings.Split(v, ".")
  25. if len(arr) < 3 {
  26. return 0
  27. }
  28. res, _ := strconv.ParseInt(arr[position], 10, 64)
  29. return res
  30. }
  31. func Proto(v string) int64 {
  32. return getSubVersion(v, 0)
  33. }
  34. func Major(v string) int64 {
  35. return getSubVersion(v, 1)
  36. }
  37. func Minor(v string) int64 {
  38. return getSubVersion(v, 2)
  39. }
  40. // add every case there if server will not accept client's protocol and return false
  41. func Compat(client string) (ok bool, msg string) {
  42. if LessThan(client, "0.10.0") {
  43. return false, "Please upgrade your frpc version to at least 0.10.0"
  44. }
  45. return true, ""
  46. }
  47. func LessThan(client string, server string) bool {
  48. vc := Proto(client)
  49. vs := Proto(server)
  50. if vc > vs {
  51. return false
  52. } else if vc < vs {
  53. return true
  54. }
  55. vc = Major(client)
  56. vs = Major(server)
  57. if vc > vs {
  58. return false
  59. } else if vc < vs {
  60. return true
  61. }
  62. vc = Minor(client)
  63. vs = Minor(server)
  64. if vc > vs {
  65. return false
  66. } else if vc < vs {
  67. return true
  68. }
  69. return false
  70. }