github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/model/version.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "fmt" 8 "strconv" 9 "strings" 10 ) 11 12 // This is a list of all the current versions including any patches. 13 // It should be maintained in chronological order with most current 14 // release at the front of the list. 15 var versions = []string{ 16 "4.10.0", 17 "4.9.0", 18 "4.8.1", 19 "4.8.0", 20 "4.7.2", 21 "4.7.1", 22 "4.7.0", 23 "4.6.0", 24 "4.5.0", 25 "4.4.0", 26 "4.3.0", 27 "4.2.0", 28 "4.1.0", 29 "4.0.0", 30 "3.10.0", 31 "3.9.0", 32 "3.8.0", 33 "3.7.0", 34 "3.6.0", 35 "3.5.0", 36 "3.4.0", 37 "3.3.0", 38 "3.2.0", 39 "3.1.0", 40 "3.0.0", 41 "2.2.0", 42 "2.1.0", 43 "2.0.0", 44 "1.4.0", 45 "1.3.0", 46 "1.2.1", 47 "1.2.0", 48 "1.1.0", 49 "1.0.0", 50 "0.7.1", 51 "0.7.0", 52 "0.6.0", 53 "0.5.0", 54 } 55 56 var CurrentVersion string = versions[0] 57 var BuildNumber string 58 var BuildDate string 59 var BuildHash string 60 var BuildHashEnterprise string 61 var BuildEnterpriseReady string 62 var versionsWithoutHotFixes []string 63 64 func init() { 65 versionsWithoutHotFixes = make([]string, 0, len(versions)) 66 seen := make(map[string]string) 67 68 for _, version := range versions { 69 maj, min, _ := SplitVersion(version) 70 verStr := fmt.Sprintf("%v.%v.0", maj, min) 71 72 if seen[verStr] == "" { 73 versionsWithoutHotFixes = append(versionsWithoutHotFixes, verStr) 74 seen[verStr] = verStr 75 } 76 } 77 } 78 79 func SplitVersion(version string) (int64, int64, int64) { 80 parts := strings.Split(version, ".") 81 82 major := int64(0) 83 minor := int64(0) 84 patch := int64(0) 85 86 if len(parts) > 0 { 87 major, _ = strconv.ParseInt(parts[0], 10, 64) 88 } 89 90 if len(parts) > 1 { 91 minor, _ = strconv.ParseInt(parts[1], 10, 64) 92 } 93 94 if len(parts) > 2 { 95 patch, _ = strconv.ParseInt(parts[2], 10, 64) 96 } 97 98 return major, minor, patch 99 } 100 101 func GetPreviousVersion(version string) string { 102 verMajor, verMinor, _ := SplitVersion(version) 103 verStr := fmt.Sprintf("%v.%v.0", verMajor, verMinor) 104 105 for index, v := range versionsWithoutHotFixes { 106 if v == verStr && len(versionsWithoutHotFixes) > index+1 { 107 return versionsWithoutHotFixes[index+1] 108 } 109 } 110 111 return "" 112 } 113 114 func IsCurrentVersion(versionToCheck string) bool { 115 currentMajor, currentMinor, _ := SplitVersion(CurrentVersion) 116 toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck) 117 118 if toCheckMajor == currentMajor && toCheckMinor == currentMinor { 119 return true 120 } else { 121 return false 122 } 123 } 124 125 func IsPreviousVersionsSupported(versionToCheck string) bool { 126 toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck) 127 versionToCheckStr := fmt.Sprintf("%v.%v.0", toCheckMajor, toCheckMinor) 128 129 // Current Supported 130 if versionsWithoutHotFixes[0] == versionToCheckStr { 131 return true 132 } 133 134 // Current - 1 Supported 135 if versionsWithoutHotFixes[1] == versionToCheckStr { 136 return true 137 } 138 139 // Current - 2 Supported 140 if versionsWithoutHotFixes[2] == versionToCheckStr { 141 return true 142 } 143 144 // Current - 3 Supported 145 if versionsWithoutHotFixes[3] == versionToCheckStr { 146 return true 147 } 148 149 return false 150 }