2017-05-05 18:02:52 +08:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2017-05-11 13:39:34 +08:00
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
|
2021-03-24 00:28:13 +08:00
|
|
|
"github.com/beego/beego/v2/core/logs"
|
2021-03-23 15:09:17 +08:00
|
|
|
"github.com/mindoc-org/mindoc/conf"
|
2017-05-05 18:02:52 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
//检查最新版本.
|
|
|
|
func CheckUpdate() {
|
|
|
|
|
2021-06-29 13:56:41 +08:00
|
|
|
fmt.Println("MinDoc current version => ", conf.VERSION)
|
|
|
|
|
|
|
|
resp, err := http.Get("https://api.github.com/repos/mindoc-org/mindoc/tags")
|
2017-06-02 16:08:14 +08:00
|
|
|
|
|
|
|
if err != nil {
|
2021-03-23 21:55:50 +08:00
|
|
|
logs.Error("CheckUpdate => ", err)
|
2017-06-02 16:08:14 +08:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
2021-03-23 21:55:50 +08:00
|
|
|
logs.Error("CheckUpdate => ", err)
|
2017-06-02 16:08:14 +08:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
var result []*struct {
|
|
|
|
Name string `json:"name"`
|
2017-05-05 18:02:52 +08:00
|
|
|
}
|
2017-06-02 16:08:14 +08:00
|
|
|
|
|
|
|
err = json.Unmarshal(body, &result)
|
|
|
|
if err != nil {
|
2021-03-23 21:55:50 +08:00
|
|
|
logs.Error("CheckUpdate => ", err)
|
2017-06-02 16:44:44 +08:00
|
|
|
os.Exit(0)
|
2017-06-02 16:08:14 +08:00
|
|
|
}
|
2017-06-02 16:44:44 +08:00
|
|
|
|
2017-06-14 09:26:32 +08:00
|
|
|
if len(result) > 0 {
|
|
|
|
fmt.Println("MinDoc last version => ", result[0].Name)
|
|
|
|
}
|
|
|
|
|
2017-06-02 16:08:14 +08:00
|
|
|
os.Exit(0)
|
|
|
|
|
2017-05-31 10:52:53 +08:00
|
|
|
}
|