forked from mindoc-org/mindoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.go
49 lines (37 loc) · 812 Bytes
/
update.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
package commands
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"github.com/beego/beego/v2/core/logs"
"github.com/mindoc-org/mindoc/conf"
)
//检查最新版本.
func CheckUpdate() {
fmt.Println("MinDoc current version => ", conf.VERSION)
resp, err := http.Get("https://api.github.com/repos/mindoc-org/mindoc/tags")
if err != nil {
logs.Error("CheckUpdate => ", err)
os.Exit(1)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
logs.Error("CheckUpdate => ", err)
os.Exit(1)
}
var result []*struct {
Name string `json:"name"`
}
err = json.Unmarshal(body, &result)
if err != nil {
logs.Error("CheckUpdate => ", err)
os.Exit(0)
}
if len(result) > 0 {
fmt.Println("MinDoc last version => ", result[0].Name)
}
os.Exit(0)
}