mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
simple version checker ✌️
Former-commit-id: 077b9c9816211c84adda864a832acf8c1296eeaf
This commit is contained in:
parent
e23f821341
commit
be8295eb50
|
@ -343,7 +343,7 @@ Below you'll find a list of open positions that require at least **experience wi
|
||||||
| -----------|--------|-------------|
|
| -----------|--------|-------------|
|
||||||
| Kudo, an Indonesian startup technology company | Application Programming Interface Developer | Navigate to: https://glints.id/opportunities/jobs/5553 |
|
| Kudo, an Indonesian startup technology company | Application Programming Interface Developer | Navigate to: https://glints.id/opportunities/jobs/5553 |
|
||||||
|
|
||||||
Employers that are looking for briliant Software Engineers with good experience on Go Programming Language and Iris can put their startup's or company's name here or, if privacy is the key, [contact with us](mailto:kataras2006@hotmail.com?subject=Employer%20That%20Hires%20Smart%20Devs) to suggest some good and well-tested freelancers that suits your needs.
|
Employers that are looking for brilliant Software Engineers with good experience on Go Programming Language and Iris can put their startup's or company's name here or, if privacy is the key, [contact with us](mailto:kataras2006@hotmail.com?subject=Employer%20That%20Hires%20Smart%20Devs) to suggest some good and well-tested freelancers that suits your needs.
|
||||||
|
|
||||||
### 🥇 People
|
### 🥇 People
|
||||||
|
|
||||||
|
|
1
VERSION
Normal file
1
VERSION
Normal file
|
@ -0,0 +1 @@
|
||||||
|
8.2.1:https://github.com/kataras/iris/blob/master/HISTORY.md#tu-08-august-2017--v821
|
|
@ -136,6 +136,11 @@ var WithoutInterruptHandler = func(app *Application) {
|
||||||
app.config.DisableInterruptHandler = true
|
app.config.DisableInterruptHandler = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithoutVersionCheck will disable the version checker and updater.
|
||||||
|
var WithoutVersionCheck = func(app *Application) {
|
||||||
|
app.config.DisableVersionCheck = true
|
||||||
|
}
|
||||||
|
|
||||||
// WithoutPathCorrection disables the PathCorrection setting.
|
// WithoutPathCorrection disables the PathCorrection setting.
|
||||||
//
|
//
|
||||||
// See `Configuration`.
|
// See `Configuration`.
|
||||||
|
@ -276,6 +281,11 @@ type Configuration struct {
|
||||||
// Defaults to false.
|
// Defaults to false.
|
||||||
DisableInterruptHandler bool `yaml:"DisableInterruptHandler" toml:"DisableInterruptHandler"`
|
DisableInterruptHandler bool `yaml:"DisableInterruptHandler" toml:"DisableInterruptHandler"`
|
||||||
|
|
||||||
|
// DisableVersionCheck if true then process will be not be notified for any available updates.
|
||||||
|
//
|
||||||
|
// Defaults to false.
|
||||||
|
DisableVersionCheck bool `yaml:"DisableVersionCheck" toml:"DisableVersionCheck"`
|
||||||
|
|
||||||
// DisablePathCorrection corrects and redirects the requested path to the registered path
|
// DisablePathCorrection corrects and redirects the requested path to the registered path
|
||||||
// for example, if /home/ path is requested but no handler for this Route found,
|
// for example, if /home/ path is requested but no handler for this Route found,
|
||||||
// then the Router checks if /home handler exists, if yes,
|
// then the Router checks if /home handler exists, if yes,
|
||||||
|
@ -597,6 +607,7 @@ func DefaultConfiguration() Configuration {
|
||||||
return Configuration{
|
return Configuration{
|
||||||
DisableStartupLog: false,
|
DisableStartupLog: false,
|
||||||
DisableInterruptHandler: false,
|
DisableInterruptHandler: false,
|
||||||
|
DisableVersionCheck: false,
|
||||||
DisablePathCorrection: false,
|
DisablePathCorrection: false,
|
||||||
EnablePathEscape: false,
|
EnablePathEscape: false,
|
||||||
FireMethodNotAllowed: false,
|
FireMethodNotAllowed: false,
|
||||||
|
|
5
iris.go
5
iris.go
|
@ -647,6 +647,11 @@ func (app *Application) Run(serve Runner, withOrWithout ...Configurator) error {
|
||||||
|
|
||||||
app.Configure(withOrWithout...)
|
app.Configure(withOrWithout...)
|
||||||
app.logger.Debugf("Application: running using %d host(s)", len(app.Hosts)+1)
|
app.logger.Debugf("Application: running using %d host(s)", len(app.Hosts)+1)
|
||||||
|
|
||||||
|
if !app.config.DisableVersionCheck && app.logger.Printer.IsTerminal {
|
||||||
|
go CheckVersion()
|
||||||
|
}
|
||||||
|
|
||||||
// this will block until an error(unless supervisor's DeferFlow called from a Task).
|
// this will block until an error(unless supervisor's DeferFlow called from a Task).
|
||||||
err := serve(app)
|
err := serve(app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -191,7 +191,7 @@ func (db *Database) destroy(bsid []byte) error {
|
||||||
// we store the whole data to the key-value pair of the root bucket
|
// we store the whole data to the key-value pair of the root bucket
|
||||||
// so we don't need a separate bucket for each session
|
// so we don't need a separate bucket for each session
|
||||||
// this method could be faster if we had large data to store
|
// this method could be faster if we had large data to store
|
||||||
// but with sessions we recommend small ammount of data, so the method finally choosen
|
// but with sessions we recommend small amount of data, so the method finally chosen
|
||||||
// is faster (decode/encode the whole store + lifetime and return it as it's)
|
// is faster (decode/encode the whole store + lifetime and return it as it's)
|
||||||
//
|
//
|
||||||
// func (db *Database) getSessBucket(tx *bolt.Tx, sid string) (*bolt.Bucket, error) {
|
// func (db *Database) getSessBucket(tx *bolt.Tx, sid string) (*bolt.Bucket, error) {
|
||||||
|
|
151
version.go
Normal file
151
version.go
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
package iris
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-version"
|
||||||
|
"github.com/kataras/golog"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
versionURL = "https://raw.githubusercontent.com/kataras/iris/master/VERSION"
|
||||||
|
updateCmd = "go get -u -f -v github.com/kataras/iris"
|
||||||
|
)
|
||||||
|
|
||||||
|
var checkVersionOnce = sync.Once{}
|
||||||
|
|
||||||
|
// CheckVersion checks for any available updates.
|
||||||
|
func CheckVersion() {
|
||||||
|
checkVersionOnce.Do(func() {
|
||||||
|
checkVersion()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkVersion() {
|
||||||
|
|
||||||
|
// open connection and read/write timeouts
|
||||||
|
timeout := time.Duration(10 * time.Second)
|
||||||
|
|
||||||
|
transport := http.Transport{
|
||||||
|
Dial: func(network string, addr string) (net.Conn, error) {
|
||||||
|
conn, err := net.DialTimeout(network, addr, timeout)
|
||||||
|
if err != nil {
|
||||||
|
golog.Debugf("%v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
conn.SetDeadline(time.Now().Add(timeout)) // skip error
|
||||||
|
return conn, nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
client := http.Client{
|
||||||
|
Transport: &transport,
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := client.Get(versionURL)
|
||||||
|
if err != nil {
|
||||||
|
golog.Debugf("%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
|
if r.StatusCode >= 400 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := ioutil.ReadAll(r.Body)
|
||||||
|
|
||||||
|
if len(b) == 0 || err != nil {
|
||||||
|
golog.Debugf("%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
fetchedVersion = string(b)
|
||||||
|
changelogURL string
|
||||||
|
)
|
||||||
|
|
||||||
|
// 8.2.1:https://github.com/kataras/iris/blob/master/HISTORY.md#tu-08-august-2017--v821
|
||||||
|
if idx := strings.IndexByte(fetchedVersion, ':'); idx > 0 {
|
||||||
|
changelogURL = fetchedVersion[idx+1:]
|
||||||
|
fetchedVersion = fetchedVersion[0:idx]
|
||||||
|
}
|
||||||
|
|
||||||
|
latestVersion, err := version.NewVersion(fetchedVersion)
|
||||||
|
if err != nil {
|
||||||
|
golog.Debugf("while parsing latest version: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
currentVersion, err := version.NewVersion(Version)
|
||||||
|
if err != nil {
|
||||||
|
golog.Debugf("while parsing current version: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentVersion.GreaterThan(latestVersion) {
|
||||||
|
golog.Debugf("current version is greater than latest version, report as bug")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentVersion.Equal(latestVersion) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// currentVersion.LessThan(latestVersion)
|
||||||
|
|
||||||
|
var updaterYesInput = [...]string{"y", "yes"}
|
||||||
|
|
||||||
|
text := "A more recent version has been found[%s > %s].\n"
|
||||||
|
|
||||||
|
if changelogURL != "" {
|
||||||
|
text += "Release notes: %s\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
text += "Update now?[%s]: "
|
||||||
|
|
||||||
|
golog.Warnf(text,
|
||||||
|
latestVersion.String(), currentVersion.String(),
|
||||||
|
changelogURL,
|
||||||
|
updaterYesInput[0]+"/n")
|
||||||
|
|
||||||
|
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 shouldUpdate {
|
||||||
|
goget := strings.Split(updateCmd, " ")
|
||||||
|
// go get -u github.com/:owner/:repo
|
||||||
|
cmd := exec.Command(goget[0], goget[1:]...)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stdout
|
||||||
|
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
golog.Warnf("unexpected message while trying to go get: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
golog.Infof("Update process finished, current version: %s.\nManual restart is required to apply the changes.\n", latestVersion.String())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user