(currentVersion string)
| 75 | } |
| 76 | |
| 77 | func checkForUpdates(currentVersion string) (bool, string) { |
| 78 | client := http.Client{ |
| 79 | Timeout: 5 * time.Second, |
| 80 | } |
| 81 | |
| 82 | resp, err := client.Get("https://api.folderhost.org/v1/folderhost/version-check") |
| 83 | if err != nil { |
| 84 | return false, currentVersion |
| 85 | } |
| 86 | defer resp.Body.Close() |
| 87 | |
| 88 | body, err := io.ReadAll(resp.Body) |
| 89 | if err != nil { |
| 90 | return false, currentVersion |
| 91 | } |
| 92 | |
| 93 | var versionResp VersionResponse |
| 94 | if err := json.Unmarshal(body, &versionResp); err != nil { |
| 95 | return false, currentVersion |
| 96 | } |
| 97 | |
| 98 | if isNewerVersion(currentVersion, versionResp.Version) { |
| 99 | return true, versionResp.Version |
| 100 | } |
| 101 | |
| 102 | return false, currentVersion |
| 103 | } |
| 104 | |
| 105 | func checkAndNotifyVersion(currentVersion string) { |
| 106 | hasUpdate, newVersion := checkForUpdates(currentVersion) |
no test coverage detected