本文整理汇总了Golang中ngrok/client/mvc.State.SetUpdateStatus方法的典型用法代码示例。如果您正苦于以下问题:Golang State.SetUpdateStatus方法的具体用法?Golang State.SetUpdateStatus怎么用?Golang State.SetUpdateStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ngrok/client/mvc.State
的用法示例。
在下文中一共展示了State.SetUpdateStatus方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: autoUpdate
func autoUpdate(s mvc.State, token string) {
up, err := update.New().VerifySignatureWithPEM([]byte(publicKey))
if err != nil {
log.Error("Failed to create update with signature: %v", err)
return
}
update := func() (tryAgain bool) {
log.Info("Checking for update")
params := check.Params{
AppId: appId,
AppVersion: version.MajorMinor(),
UserId: token,
}
result, err := params.CheckForUpdate(updateEndpoint, up)
if err == check.NoUpdateAvailable {
log.Info("No update available")
return true
} else if err != nil {
log.Error("Error while checking for update: %v", err)
return true
}
if result.Initiative == check.INITIATIVE_AUTO {
if err := up.CanUpdate(); err != nil {
log.Error("Can't update: insufficient permissions: %v", err)
// tell the user to update manually
s.SetUpdateStatus(mvc.UpdateAvailable)
} else {
applyUpdate(s, result)
}
} else if result.Initiative == check.INITIATIVE_MANUAL {
// this is the way the server tells us to update manually
log.Info("Server wants us to update manually")
s.SetUpdateStatus(mvc.UpdateAvailable)
} else {
log.Info("Update available, but ignoring")
}
// stop trying after a single download attempt
// XXX: improve this so the we can:
// 1. safely update multiple times
// 2. only retry after temporary errors
return false
}
// try to update immediately and then at a set interval
for {
if tryAgain := update(); !tryAgain {
break
}
time.Sleep(updateCheckInterval)
}
}
示例2: applyUpdate
func applyUpdate(s mvc.State, result *check.Result) {
err, errRecover := result.Update()
if err == nil {
log.Info("Update ready!")
s.SetUpdateStatus(mvc.UpdateReady)
return
}
log.Error("Error while updating ngrok: %v", err)
if errRecover != nil {
log.Error("Error while recovering from failed ngrok update, your binary may be missing: %v", errRecover.Error())
}
// tell the user to update manually
s.SetUpdateStatus(mvc.UpdateAvailable)
}
示例3: progressWatcher
func progressWatcher(s mvc.State, progress chan int, complete chan int) {
for {
select {
case pct, ok := <-progress:
if !ok {
close(complete)
return
} else if pct == 100 {
s.SetUpdateStatus(mvc.UpdateInstalling)
close(complete)
return
} else {
if pct%25 == 0 {
log.Info("Downloading update %d%% complete", pct)
}
s.SetUpdateStatus(mvc.UpdateStatus(pct))
}
}
}
}
示例4: autoUpdate
func autoUpdate(s mvc.State, token string) {
tryAgain := true
params := make(url.Values)
params.Add("version", version.MajorMinor())
params.Add("os", runtime.GOOS)
params.Add("arch", runtime.GOARCH)
params.Add("user", token)
updateUrl := updateEndpoint + "?" + params.Encode()
checkUrl := checkEndpoint + "?" + params.Encode()
update := func() {
log.Info("Checking for update")
available, err := update.NewDownload(checkUrl).Check()
if err != nil {
log.Error("Error while checking for update: %v", err)
return
}
if !available {
log.Info("No update available")
return
}
// stop trying after a single download attempt
// XXX: improve this so the we can:
// 1. safely update multiple times
// 2. only retry after a network connection failure
tryAgain = false
download := update.NewDownload(updateUrl)
downloadComplete := make(chan int)
go progressWatcher(s, download.Progress, downloadComplete)
log.Info("Trying to update . . .")
err, errRecover := download.GetAndUpdate()
<-downloadComplete
if err != nil {
// log error to console
log.Error("Error while updating ngrok: %v", err)
if errRecover != nil {
log.Error("Error while recovering from failed ngrok update, your binary may be missing: %v", errRecover.Error())
params.Add("errorRecover", errRecover.Error())
}
// log error to ngrok.com's servers for debugging purposes
params.Add("error", err.Error())
resp, reportErr := http.PostForm("https://dl.ngrok.com/update/error", params)
if err != nil {
log.Error("Error while reporting update error: %v, %v", err, reportErr)
}
resp.Body.Close()
// tell the user to update manually
s.SetUpdateStatus(mvc.UpdateAvailable)
} else {
if !download.Available {
// this is the way the server tells us to update manually
log.Info("Server wants us to update manually")
s.SetUpdateStatus(mvc.UpdateAvailable)
} else {
// tell the user the update is ready
log.Info("Update ready!")
s.SetUpdateStatus(mvc.UpdateReady)
}
}
return
}
// try to update immediately and then at a set interval
update()
for _ = range time.Tick(updateCheckInterval) {
if !tryAgain {
break
}
update()
}
}