(isLatest bool, currentVersion, mode string)
| 101 | } |
| 102 | |
| 103 | func loadVersion(isLatest bool, currentVersion, mode string) string { |
| 104 | path := fmt.Sprintf("%s/%s/latest", global.RepoURL(), mode) |
| 105 | if !isLatest { |
| 106 | path = fmt.Sprintf("%s/%s/latest.current", global.RepoURL(), mode) |
| 107 | } |
| 108 | _, latestVersionRes, err := HandleRequest(path, http.MethodGet, constant.TimeOut20s) |
| 109 | if err != nil { |
| 110 | global.LOG.Errorf("load latest version from oss failed, err: %v", err) |
| 111 | return "" |
| 112 | } |
| 113 | version := string(latestVersionRes) |
| 114 | if strings.Contains(version, "<") { |
| 115 | global.LOG.Errorf("load latest version from oss failed, err: %v", version) |
| 116 | return "" |
| 117 | } |
| 118 | if isLatest { |
| 119 | return checkVersion(version, currentVersion) |
| 120 | } |
| 121 | |
| 122 | versionMap := make(map[string]string) |
| 123 | if err := json.Unmarshal(latestVersionRes, &versionMap); err != nil { |
| 124 | global.LOG.Errorf("load latest version from oss failed (error unmarshal), err: %v", err) |
| 125 | return "" |
| 126 | } |
| 127 | |
| 128 | versionPart := strings.Split(currentVersion, ".") |
| 129 | if len(versionPart) < 3 { |
| 130 | global.LOG.Errorf("current version is error format: %s", currentVersion) |
| 131 | return "" |
| 132 | } |
| 133 | num, _ := strconv.Atoi(versionPart[1]) |
| 134 | if num >= 10 { |
| 135 | if version, ok := versionMap[currentVersion[0:5]]; ok { |
| 136 | return checkVersion(version, currentVersion) |
| 137 | } |
| 138 | return "" |
| 139 | } |
| 140 | if version, ok := versionMap[currentVersion[0:4]]; ok { |
| 141 | return checkVersion(version, currentVersion) |
| 142 | } |
| 143 | return "" |
| 144 | } |
| 145 | |
| 146 | func checkVersion(v2, v1 string) string { |
| 147 | addSuffix := false |
no test coverage detected