1 Star 0 Fork 18

justin/ebookdownloader

forked from sndnvaps/ebookdownloader 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
updateChecker.go 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
sndnvaps 提交于 2020-03-01 21:00 . 更新版本到v1.7.3
package ebookdownloader
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
)
//LatestReleasesInfo 获取最新的Releases信息
type LatestReleasesInfo struct {
URL string `json:"html_url"`
Tag string `json:"tag_name"`
}
//String ReleaseInfo String()
func (ri LatestReleasesInfo) String() string {
return fmt.Sprintf("Latest version is %s: %s", ri.Tag, ri.URL)
}
//Compare 对版本进行对比
func (ri LatestReleasesInfo) Compare(CurVersion string) string {
if CurVersion != "dev" {
if !strings.HasPrefix(CurVersion, ri.Tag) {
return fmt.Sprintf("Running version %s. Latest version is %s: %s\n", CurVersion, ri.Tag, ri.URL)
}
}
return fmt.Sprintf("Not need to update! Running version %s. Latest version is %s: %s\n", CurVersion, ri.Tag, ri.URL)
}
//UpdateCheck 检查更新
func UpdateCheck() (obj LatestReleasesInfo, err error) {
resp, err := http.Get("https://api.github.com/repos/sndnvaps/ebookdownloader/releases/latest")
if err != nil {
return LatestReleasesInfo{}, err
}
defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
return LatestReleasesInfo{}, err
}
if resp.StatusCode != 200 {
return LatestReleasesInfo{}, err
}
err = json.Unmarshal(buf, &obj)
if err != nil {
return LatestReleasesInfo{}, err
}
return obj, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jostin/ebookdownloader.git
git@gitee.com:jostin/ebookdownloader.git
jostin
ebookdownloader
ebookdownloader
master

搜索帮助