version.go 892 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * @Author: LinkLeong link@icewhale.com
  3. * @Date: 2022-05-13 18:15:46
  4. * @LastEditors: LinkLeong
  5. * @LastEditTime: 2022-07-21 15:27:53
  6. * @FilePath: /CasaOS/pkg/utils/version/version.go
  7. * @Description:
  8. * @Website: https://www.casaos.io
  9. * Copyright (c) 2022 by icewhale, All Rights Reserved.
  10. */
  11. package version
  12. import (
  13. "strconv"
  14. "strings"
  15. "github.com/IceWhaleTech/CasaOS/common"
  16. "github.com/IceWhaleTech/CasaOS/model"
  17. )
  18. func IsNeedUpdate(version model.Version) (bool, model.Version) {
  19. v1 := strings.Split(version.Version, ".")
  20. v2 := strings.Split(common.VERSION, ".")
  21. for len(v1) < len(v2) {
  22. v1 = append(v1, "0")
  23. }
  24. for len(v2) < len(v1) {
  25. v2 = append(v2, "0")
  26. }
  27. for i := 0; i < len(v1); i++ {
  28. a, _ := strconv.Atoi(v1[i])
  29. b, _ := strconv.Atoi(v2[i])
  30. if a > b {
  31. return true, version
  32. }
  33. if a < b {
  34. return false, version
  35. }
  36. }
  37. return false, version
  38. }