version.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.10.0"
  20. func Full() string {
  21. return version
  22. }
  23. func Proto(v string) int64 {
  24. arr := strings.Split(v, ".")
  25. if len(arr) < 3 {
  26. return 0
  27. }
  28. res, _ := strconv.ParseInt(arr[0], 10, 64)
  29. return res
  30. }
  31. func Major(v string) int64 {
  32. arr := strings.Split(v, ".")
  33. if len(arr) < 3 {
  34. return 0
  35. }
  36. res, _ := strconv.ParseInt(arr[1], 10, 64)
  37. return res
  38. }
  39. func Minor(v string) int64 {
  40. arr := strings.Split(v, ".")
  41. if len(arr) < 3 {
  42. return 0
  43. }
  44. res, _ := strconv.ParseInt(arr[2], 10, 64)
  45. return res
  46. }
  47. // add every case there if server will not accept client's protocol and return false
  48. func Compat(client string) (ok bool, msg string) {
  49. if LessThan(client, version) {
  50. return false, "Please upgrade your frpc version to 0.10.0"
  51. }
  52. return true, ""
  53. }
  54. func LessThan(client string, server string) bool {
  55. vc := Proto(client)
  56. vs := Proto(server)
  57. if vc > vs {
  58. return false
  59. } else if vc < vs {
  60. return true
  61. }
  62. vc = Major(client)
  63. vs = Major(server)
  64. if vc > vs {
  65. return false
  66. } else if vc < vs {
  67. return true
  68. }
  69. vc = Minor(client)
  70. vs = Minor(server)
  71. if vc > vs {
  72. return false
  73. } else if vc < vs {
  74. return true
  75. }
  76. return false
  77. }