mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 11:06:27 +01:00
remove old deprecated code from previous version, no need to keep backward compatibility, it was two months ago v10.0.0 released so we should be ok now
Former-commit-id: 81ac9d4913e78154b4bb74a01ce707b510e674ec
This commit is contained in:
parent
7fd8baea75
commit
fce7959424
|
@ -1,93 +0,0 @@
|
||||||
package maintenance
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
|
||||||
|
|
||||||
"github.com/kataras/iris/core/maintenance/client"
|
|
||||||
"github.com/kataras/iris/core/maintenance/encoding"
|
|
||||||
|
|
||||||
"github.com/kataras/survey"
|
|
||||||
)
|
|
||||||
|
|
||||||
// question describes the question which will be used
|
|
||||||
// for the survey in order to authenticate the local iris.
|
|
||||||
type question struct {
|
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func hasInternetConnection() (bool, bool) {
|
|
||||||
r, err := client.PostForm("", nil)
|
|
||||||
if err != nil {
|
|
||||||
// no internet connection
|
|
||||||
return false, false
|
|
||||||
}
|
|
||||||
defer r.Body.Close()
|
|
||||||
return true, r.StatusCode == 204
|
|
||||||
}
|
|
||||||
|
|
||||||
func ask() bool {
|
|
||||||
qs := fetchQuestions()
|
|
||||||
var lastResponseUnsed string
|
|
||||||
for _, q := range qs {
|
|
||||||
survey.AskOne(&survey.Input{Message: q.Message}, &lastResponseUnsed, validate(q))
|
|
||||||
}
|
|
||||||
|
|
||||||
return lastResponseUnsed != ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetchQuestions returns a list of questions
|
|
||||||
// fetched by the authority server.
|
|
||||||
func fetchQuestions() (qs []question) {
|
|
||||||
r, err := client.PostForm("/survey/ask", nil)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer r.Body.Close()
|
|
||||||
if err := encoding.UnmarshalBody(r.Body, &qs, json.Unmarshal); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func validate(q question) survey.Validator {
|
|
||||||
return func(answer interface{}) error {
|
|
||||||
if err := survey.Required(answer); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ans, ok := answer.(string)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("bug: expected string but got %v", answer)
|
|
||||||
}
|
|
||||||
data := url.Values{
|
|
||||||
"q": []string{q.Message},
|
|
||||||
"ans": []string{ans},
|
|
||||||
"current_version": []string{Version},
|
|
||||||
}
|
|
||||||
|
|
||||||
r, err := client.PostForm("/survey/submit", data)
|
|
||||||
if err != nil {
|
|
||||||
// error from server-side, allow.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
defer r.Body.Close()
|
|
||||||
|
|
||||||
if r.StatusCode == 200 {
|
|
||||||
// read the whole thing, it has nothing.
|
|
||||||
io.Copy(ioutil.Discard, r.Body)
|
|
||||||
return nil // pass, no any errors.
|
|
||||||
}
|
|
||||||
// now, if invalid;
|
|
||||||
got, err := ioutil.ReadAll(r.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
errMsg := string(got)
|
|
||||||
return fmt.Errorf(errMsg)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
package client
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"os/user"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/kataras/iris/core/netutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
const host = "https://live.iris-go.com"
|
|
||||||
|
|
||||||
// PostForm performs the PostForm with a secure client.
|
|
||||||
func PostForm(p string, data url.Values) (*http.Response, error) {
|
|
||||||
client := netutil.Client(25 * time.Second)
|
|
||||||
|
|
||||||
if len(data) == 0 {
|
|
||||||
data = make(url.Values, 1)
|
|
||||||
}
|
|
||||||
un, _ := user.Current()
|
|
||||||
if un != nil {
|
|
||||||
a += "_" + un.Name
|
|
||||||
}
|
|
||||||
data.Set("X-Auth", url.QueryEscape(a))
|
|
||||||
|
|
||||||
u := host + p
|
|
||||||
r, err := client.PostForm(u, data)
|
|
||||||
return r, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var a string
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
interfaces, err := net.Interfaces()
|
|
||||||
if err == nil {
|
|
||||||
for _, f := range interfaces {
|
|
||||||
if f.Flags&net.FlagUp != 0 && bytes.Compare(f.HardwareAddr, nil) != 0 {
|
|
||||||
a = f.HardwareAddr.String()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package encoding
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
// UnmarshalerFunc is the Unmarshaler compatible type.
|
|
||||||
//
|
|
||||||
// See 'unmarshalBody' for more.
|
|
||||||
type UnmarshalerFunc func(data []byte, v interface{}) error
|
|
||||||
|
|
||||||
// UnmarshalBody reads the request's body and binds it to a value or pointer of any type.
|
|
||||||
func UnmarshalBody(body io.Reader, v interface{}, unmarshaler UnmarshalerFunc) error {
|
|
||||||
if body == nil {
|
|
||||||
return errors.New("unmarshal: empty body")
|
|
||||||
}
|
|
||||||
|
|
||||||
rawData, err := ioutil.ReadAll(body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if v is already a pointer, if yes then pass as it's
|
|
||||||
if reflect.TypeOf(v).Kind() == reflect.Ptr {
|
|
||||||
return unmarshaler(rawData, v)
|
|
||||||
}
|
|
||||||
// finally, if the v doesn't contains a self-body decoder and it's not a pointer
|
|
||||||
// use the custom unmarshaler to bind the body
|
|
||||||
return unmarshaler(rawData, &v)
|
|
||||||
}
|
|
|
@ -19,34 +19,25 @@ const (
|
||||||
// CheckForUpdates checks for any available updates
|
// CheckForUpdates checks for any available updates
|
||||||
// and asks for the user if want to update now or not.
|
// and asks for the user if want to update now or not.
|
||||||
func CheckForUpdates(ft bool) {
|
func CheckForUpdates(ft bool) {
|
||||||
has := true
|
|
||||||
if ft {
|
|
||||||
has, ft = hasInternetConnection()
|
|
||||||
}
|
|
||||||
|
|
||||||
v := version.Acquire()
|
v := version.Acquire()
|
||||||
updateAvailale := v.Compare(Version) == version.Smaller
|
updateAvailale := v.Compare(Version) == version.Smaller
|
||||||
|
|
||||||
if updateAvailale {
|
if updateAvailale {
|
||||||
if confirmUpdate(v) {
|
if confirmUpdate(v) {
|
||||||
canUpdate := (has && ft && ask()) || !has || !ft
|
installVersion()
|
||||||
if canUpdate {
|
return
|
||||||
installVersion()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func confirmUpdate(v version.Version) bool {
|
func confirmUpdate(v version.Version) bool {
|
||||||
// on help? when asking for installing the new update
|
// 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)"
|
ignoreUpdatesMsg := "Would you like to ignore future updates? Disable the version checker via:\napp.Run(..., iris.WithoutVersionChecker)"
|
||||||
|
|
||||||
// if update available ask for update action.
|
// if update available ask for update action.
|
||||||
shouldUpdateNowMsg :=
|
shouldUpdateNowMsg :=
|
||||||
fmt.Sprintf("A new version is available online[%s < %s].\nRelease notes: %s.\nUpdate now?",
|
fmt.Sprintf("A new version is available online[%s > %s]. Type '?' for help.\nRelease notes: %s.\nUpdate now?",
|
||||||
Version, v.String(),
|
v.String(), Version, v.ChangelogURL)
|
||||||
v.ChangelogURL)
|
|
||||||
|
|
||||||
var confirmUpdate bool
|
var confirmUpdate bool
|
||||||
survey.AskOne(&survey.Confirm{
|
survey.AskOne(&survey.Confirm{
|
||||||
|
|
|
@ -1,55 +1 @@
|
||||||
package iris
|
package iris
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/kataras/iris/core/router"
|
|
||||||
"github.com/kataras/iris/mvc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Controller method is DEPRECATED, use the "mvc" subpackage instead, i.e
|
|
||||||
// import "github.com/kataras/iris/mvc" and read its docs among with its new features at:
|
|
||||||
// https://github.com/kataras/iris/blob/master/HISTORY.md#mo-01-jenuary-2018--v1000
|
|
||||||
func (app *Application) Controller(relPath string, c interface{}, _ ...interface{}) []*router.Route {
|
|
||||||
name := mvc.NameOf(c)
|
|
||||||
|
|
||||||
panic(fmt.Errorf(`"Controller" method is DEPRECATED, use the "mvc" subpackage instead.
|
|
||||||
|
|
||||||
PREVIOUSLY YOU USED TO CODE IT LIKE THIS:
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/kataras/iris"
|
|
||||||
// ...
|
|
||||||
)
|
|
||||||
|
|
||||||
app.Controller("%s", new(%s), Struct_Values_Binded_To_The_Fields_Or_And_Any_Middleware)
|
|
||||||
|
|
||||||
NOW YOU SHOULD CODE IT LIKE THIS:
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/kataras/iris"
|
|
||||||
"github.com/kataras/iris/mvc"
|
|
||||||
// ...
|
|
||||||
)
|
|
||||||
|
|
||||||
// or use it like this: ).Register(...).Handle(new(%s))
|
|
||||||
mvc.Configure(app.Party("%s"), myMVC)
|
|
||||||
|
|
||||||
func myMVC(mvcApp *mvc.Application) {
|
|
||||||
mvcApp.Register(
|
|
||||||
Struct_Values_Dependencies_Binded_To_The_Fields_Or_And_To_Methods,
|
|
||||||
Or_And_Func_Values_Dependencies_Binded_To_The_Fields_Or_And_To_Methods,
|
|
||||||
)
|
|
||||||
|
|
||||||
mvcApp.Router.Use(Any_Middleware)
|
|
||||||
|
|
||||||
mvcApp.Handle(new(%s))
|
|
||||||
}
|
|
||||||
|
|
||||||
The new MVC implementation contains a lot more than the above,
|
|
||||||
this is the reason you see more lines for a simple controller.
|
|
||||||
|
|
||||||
Please read more about the newest, amazing, features by navigating below
|
|
||||||
https://github.com/kataras/iris/blob/master/HISTORY.md#mo-01-jenuary-2018--v1000`, // v10.0.0, we skip the number 9.
|
|
||||||
relPath, name, name, relPath, name))
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user