mindoc/commands/update.go

46 lines
772 B
Go
Raw Normal View History

2017-05-05 18:02:52 +08:00
package commands
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"github.com/astaxie/beego"
"github.com/lifei6671/godoc/conf"
2017-05-05 18:02:52 +08:00
)
//检查最新版本.
func CheckUpdate() {
resp, err := http.Get("https://api.github.com/repos/lifei6671/godoc/tags")
if err != nil {
beego.Error("CheckUpdate => ", err)
os.Exit(1)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
beego.Error("CheckUpdate => ", err)
os.Exit(1)
}
var result []*struct {
Name string `json:"name"`
2017-05-05 18:02:52 +08:00
}
err = json.Unmarshal(body, &result)
2017-06-02 16:44:44 +08:00
fmt.Println("MinDoc current version => ", conf.VERSION)
if err != nil {
beego.Error("CheckUpdate => ", err)
2017-06-02 16:44:44 +08:00
os.Exit(0)
}
2017-06-02 16:44:44 +08:00
fmt.Println("MinDoc last version => ", result[0].Name)
os.Exit(0)
2017-05-31 10:52:53 +08:00
}