1 Star 1 Fork 0

bon-ami / eztools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
appup.go 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
package eztools
import (
"database/sql"
"github.com/sanbornm/go-selfupdate/selfupdate"
)
// AppUpgrade checks for updates and applies the update automatically,
// which will work next time the app is run.
// ch: 1st=false, if wrong server URL configured.
// 2nd=false, if other configurations wrong, or update check fails.
func AppUpgrade(db *sql.DB, prefix string, ver string, server *chan string, ch chan bool) {
type pairs struct {
id string
str string
}
upPairs := []pairs{
{
"Url", "",
},
{
"Dir", "",
},
{
"App", "",
},
}
if ver == "dev" {
upPairs[0].id += "Dev"
}
var (
upStr string
err error
)
for i, upPair := range upPairs {
upStr, err = GetPairStr(db, TblCHORE, prefix+upPair.id)
if err == nil && len(upStr) > 0 {
upPairs[i].str = upStr
} else {
var log func(...interface{})
if Verbose > 0 {
log = LogPrint
} else {
log = Log
}
log("NO " + prefix + upPair.id + " configured!")
if err != nil {
LogErrPrint(err)
}
break
}
}
if len(upPairs[0].str) < 1 {
Log("update check response mal-configured")
ch <- false
return
}
if Debugging && Verbose > 2 {
Log("update check response temp")
}
ch <- true
if server != nil {
*server <- upPairs[0].str
}
if len(upPairs[1].str) < 1 || len(upPairs[2].str) < 1 {
ch <- false
Log("update check response final failure")
return
}
var updater = &selfupdate.Updater{
CurrentVersion: ver,
ApiURL: upPairs[0].str,
BinURL: upPairs[0].str,
DiffURL: upPairs[0].str,
Dir: upPairs[1].str,
CmdName: upPairs[2].str,
ForceCheck: true,
}
if ver == "ro" || len(ver) < 1 {
if Verbose > 0 {
ShowStrln("update skipped for ro or nil versions.")
}
ch <- true
return
}
if err = updater.BackgroundRun(); err != nil {
if Verbose > 0 {
ShowStrln("Failed to check update for this app")
}
LogErr(err)
if Debugging && Verbose > 2 {
Log("update check response final")
}
ch <- false
}
if len(updater.Info.Version) > 0 && ver != updater.Info.Version {
if Verbose > 0 {
ShowStrln("On the next run, this app will be updated to " + updater.Info.Version)
}
}
ch <- true
return
}
Go
1
https://gitee.com/bon-ami/eztools.git
git@gitee.com:bon-ami/eztools.git
bon-ami
eztools
eztools
main

搜索帮助