1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-20 03:17:04 +00:00

Organising kataras/go-fs. No api changes for these changes don't worry. See previous commit's description for more info.

Former-commit-id: 8af960e5e4e5f7c8816140ac912328b9c524370b
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-03-01 19:17:32 +02:00
parent 57aea4aa75
commit a6fc0072ff
8 changed files with 392 additions and 74 deletions

46
iris.go
View File

@@ -27,7 +27,6 @@ import (
"github.com/geekypanda/httpcache"
"github.com/kataras/go-errors"
"github.com/kataras/go-fs"
)
const (
@@ -353,7 +352,7 @@ func New(setters ...OptionSetter) *Framework {
// On Build: local repository updates
s.Adapt(EventPolicy{Build: func(*Framework) {
if s.Config.CheckForUpdates {
go s.CheckForUpdates(false)
go CheckForUpdates(false)
}
}})
}
@@ -671,49 +670,6 @@ func (s *Framework) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.Router.ServeHTTP(w, r)
}
// global once because is not necessary to check for updates on more than one iris station*
var updateOnce sync.Once
const (
githubOwner = "kataras"
githubRepo = "iris"
)
// CheckForUpdates will try to search for newer version of Iris based on the https://github.com/kataras/iris/releases
// If a newer version found then the app will ask the he dev/user if want to update the 'x' version
// if 'y' is pressed then the updater will try to install the latest version
// the updater, will notify the dev/user that the update is finished and should restart the App manually.
// Note: exported func CheckForUpdates exists because of the reason that an update can be executed while Iris is running
func (s *Framework) CheckForUpdates(force bool) {
updated := false
checker := func() {
fs.DefaultUpdaterAlreadyInstalledMessage = "Updater: Running with the latest version(%s)\n"
updater, err := fs.GetUpdater(githubOwner, githubRepo, Version)
if err != nil {
// ignore writer's error
s.Log(DevMode, "update failed: "+err.Error())
return
}
updated = updater.Run(fs.Stdout(s.policies.LoggerPolicy), fs.Stderr(s.policies.LoggerPolicy), fs.Silent(false))
}
if force {
checker()
} else {
updateOnce.Do(checker)
}
if updated { // if updated, then do not run the web server
s.Log(DevMode, "exiting now...")
os.Exit(1)
}
}
// Adapt adapds a policy to the Framework.
// It accepts single or more objects that implements the iris.Policy.
// Iris provides some of them but you can build your own based on one or more of these: