mirror of
https://github.com/kataras/iris.git
synced 2026-01-10 05:25:58 +00:00
Update to version 8.5.4 | Read HISTORY.md
https://github.com/kataras/iris/blob/master/HISTORY.md#th-26-october-2017--v854 Former-commit-id: 43a3b46b99085e0e0ed47b281e2f61dbb1ac6eb6
This commit is contained in:
113
version.go
113
version.go
@@ -1,8 +1,8 @@
|
||||
package iris
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -12,6 +12,9 @@ import (
|
||||
|
||||
"github.com/kataras/golog"
|
||||
"github.com/kataras/iris/core/netutil"
|
||||
"github.com/kataras/survey"
|
||||
|
||||
"github.com/skratchdot/open-golang/open"
|
||||
)
|
||||
|
||||
var checkVersionOnce = sync.Once{}
|
||||
@@ -27,10 +30,11 @@ type versionInfo struct {
|
||||
Version string `json:"version"`
|
||||
ChangelogURL string `json:"changelog_url"`
|
||||
UpdateAvailable bool `json:"update_available"`
|
||||
FirstTime bool `json:"first_time"`
|
||||
}
|
||||
|
||||
func checkVersion() {
|
||||
client := netutil.Client(20 * time.Second)
|
||||
client := netutil.Client(30 * time.Second)
|
||||
r, err := client.PostForm("https://iris-go.com/version", url.Values{"current_version": {Version}})
|
||||
|
||||
if err != nil {
|
||||
@@ -60,45 +64,88 @@ func checkVersion() {
|
||||
return
|
||||
}
|
||||
|
||||
format := "A new version is available online[%s > %s].\n"
|
||||
// shouldUpdate := false
|
||||
// prompt := &survey.Confirm{
|
||||
// Message: shouldUpdateNowMsg,
|
||||
// }
|
||||
|
||||
if v.ChangelogURL != "" {
|
||||
format += "Release notes: %s\n"
|
||||
// if err := survey.AskOne(prompt, &shouldUpdate, nil); err != nil {
|
||||
// return
|
||||
// }
|
||||
var qs []*survey.Question
|
||||
|
||||
// on help? when asking for installing the new update
|
||||
// and when answering "No".
|
||||
ignoreUpdatesMsg := "Would you like to ignore future updates? Disable the version checker via:\napp.Run(..., iris.WithoutVersionChecker)"
|
||||
|
||||
if v.UpdateAvailable {
|
||||
// if update available ask for update action.
|
||||
shouldUpdateNowMsg :=
|
||||
fmt.Sprintf("A new version is available online[%s > %s].\nRelease notes: %s.\nUpdate now?",
|
||||
v.Version, Version,
|
||||
v.ChangelogURL)
|
||||
|
||||
qs = append(qs, &survey.Question{
|
||||
Name: "shouldUpdateNow",
|
||||
Prompt: &survey.Confirm{
|
||||
Message: shouldUpdateNowMsg,
|
||||
Help: ignoreUpdatesMsg,
|
||||
},
|
||||
Validate: survey.Required,
|
||||
})
|
||||
}
|
||||
|
||||
format += "Update now?[%s]: "
|
||||
// firs time and update available is not relative because if no update often server will decide when to ask this,
|
||||
// so separate the actions and if statements here.
|
||||
if v.FirstTime {
|
||||
// if first time that this server was updated then ask if enjoying the framework.
|
||||
qs = append(qs, &survey.Question{
|
||||
Name: "enjoyingIris",
|
||||
Prompt: &survey.Confirm{
|
||||
Message: "Enjoying Iris Framework?",
|
||||
Help: "yes or no",
|
||||
},
|
||||
Validate: survey.Required,
|
||||
})
|
||||
}
|
||||
|
||||
// currentVersion.LessThan(latestVersion)
|
||||
updaterYesInput := [...]string{"y", "yes"}
|
||||
// Ask if should update(if available) and enjoying iris(if first time) in the same survey.
|
||||
ans := struct {
|
||||
ShouldUpdateNow bool `survey:"shouldUpdateNow"`
|
||||
EnjoyingIris bool `survey:"enjoyingIris"`
|
||||
}{}
|
||||
|
||||
golog.Warnf(format, v.Version, Version,
|
||||
v.ChangelogURL,
|
||||
updaterYesInput[0]+"/n")
|
||||
survey.Ask(qs, &ans)
|
||||
|
||||
silent := false
|
||||
|
||||
sc := bufio.NewScanner(os.Stdin)
|
||||
|
||||
shouldUpdate := silent
|
||||
|
||||
if !silent {
|
||||
if sc.Scan() {
|
||||
inputText := sc.Text()
|
||||
|
||||
for _, s := range updaterYesInput {
|
||||
if inputText == s {
|
||||
shouldUpdate = true
|
||||
}
|
||||
if ans.EnjoyingIris {
|
||||
// if the answer to the previous survey about enjoying the framework
|
||||
// was positive then do the survey (currently only one question and its action).
|
||||
qs2 := []*survey.Question{
|
||||
{
|
||||
Name: "starNow",
|
||||
Prompt: &survey.Confirm{
|
||||
Message: "Would you mind giving us a star on GitHub? It really helps us out! Thanks for your support:)",
|
||||
Help: "Its free so let's do that, type 'y'",
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
/* any future questions should be here, at this second survey. */
|
||||
}
|
||||
ans2 := struct {
|
||||
StarNow bool `survey:"starNow"`
|
||||
}{}
|
||||
survey.Ask(qs2, &ans2)
|
||||
if ans2.StarNow {
|
||||
starRepo := "https://github.com/kataras/iris/stargazers"
|
||||
if err := open.Run(starRepo); err != nil {
|
||||
golog.Warnf("tried to open the browser for you but failed, please give us a star at: %s\n", starRepo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !shouldUpdate {
|
||||
golog.Infof("Ignore updates? Disable version checker via:\napp.Run(..., iris.WithoutVersionChecker)")
|
||||
return
|
||||
}
|
||||
|
||||
if shouldUpdate {
|
||||
// run the updater last, so the user can star the repo and at the same time
|
||||
// the app will update her/his local iris.
|
||||
if ans.ShouldUpdateNow { // it's true only when update was available and user typed "yes".
|
||||
repo := "github.com/kataras/iris/..."
|
||||
cmd := exec.Command("go", "get", "-u", "-v", repo)
|
||||
cmd.Stdout = os.Stdout
|
||||
@@ -109,6 +156,8 @@ func checkVersion() {
|
||||
return
|
||||
}
|
||||
|
||||
golog.Infof("Update process finished.\nManual rebuild and restart is required to apply the changes...")
|
||||
golog.Infof("Update process finished.\nManual rebuild and restart is required to apply the changes...\n")
|
||||
} else {
|
||||
golog.Infof(ignoreUpdatesMsg)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user