-
Notifications
You must be signed in to change notification settings - Fork 2
/
version.go
53 lines (41 loc) · 1.04 KB
/
version.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
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"github.com/fatih/color"
"github.com/hashicorp/go-version"
)
var AppVersion string = "0.0.0"
var latestRelease string = "https://github.com/nhinv11/veracode-dotnet-packager/releases/latest"
func notifyOfUpdates() {
client := &http.Client{}
req, err := http.NewRequest("GET", latestRelease, 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
}
vCurrent, err := version.NewVersion(AppVersion)
vLatest, err := version.NewVersion(response["tag_name"].(string))
// check if a newer version exists
if vCurrent.LessThan(vLatest) {
color.HiYellow(fmt.Sprintf("Please upgrade to the latest version of this tool (%s) by visiting %s\n\n", response["tag_name"], latestRelease))
}
}