1
0

update.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package update
  2. /*
  3. Update.go
  4. This module handle cross version updates that contains breaking changes
  5. update command should always exit after the update is completed
  6. */
  7. import (
  8. "fmt"
  9. "strconv"
  10. "strings"
  11. v308 "imuslab.com/zoraxy/mod/update/v308"
  12. )
  13. // Run config update. Version numbers are int. For example
  14. // to update 3.0.7 to 3.0.8, use RunConfigUpdate(307, 308)
  15. // This function support cross versions updates (e.g. 307 -> 310)
  16. func RunConfigUpdate(fromVersion int, toVersion int) {
  17. for i := fromVersion; i < toVersion; i++ {
  18. oldVersion := fromVersion
  19. newVersion := fromVersion + 1
  20. fmt.Println("Updating from v", oldVersion, " to v", newVersion)
  21. runUpdateRoutineWithVersion(oldVersion, newVersion)
  22. }
  23. fmt.Println("Update completed")
  24. }
  25. func GetVersionIntFromVersionNumber(version string) int {
  26. versionNumberOnly := strings.ReplaceAll(version, ".", "")
  27. versionInt, _ := strconv.Atoi(versionNumberOnly)
  28. return versionInt
  29. }
  30. func runUpdateRoutineWithVersion(fromVersion int, toVersion int) {
  31. if fromVersion == 307 && toVersion == 308 {
  32. err := v308.UpdateFrom307To308()
  33. if err != nil {
  34. panic(err)
  35. }
  36. }
  37. }