代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。