-
Notifications
You must be signed in to change notification settings - Fork 9
/
version_check.go
65 lines (46 loc) · 1.13 KB
/
version_check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"encoding/json"
"fmt"
"github.com/veracode/scan_health/v2/utils"
"io"
"net/http"
"github.com/fatih/color"
)
//goland:noinspection GoUnnecessarilyExportedIdentifiers
var AppVersion = "0.0"
func notifyOfUpdates() {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://github.com/veracode/scan_health/releases/latest", nil)
if err != nil {
return
}
req.Header.Add("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
return
}
if resp.StatusCode != http.StatusOK {
return
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return
}
var response map[string]interface{}
err = json.Unmarshal(body, &response)
if err != nil {
return
}
latestReleasedVersion, err := utils.StringToFloat(response["tag_name"].(string))
if err != nil {
return
}
appVersion, err := utils.StringToFloat(AppVersion)
if err != nil {
return
}
if latestReleasedVersion > appVersion {
color.HiYellow(fmt.Sprintf("Please upgrade to the latest version of this tool (v%s) by visiting https://github.com/veracode/scan_health/releases/latest\n", response["tag_name"]))
}
}