diff --git a/core/maintenance/authenticate.go b/core/maintenance/authenticate.go deleted file mode 100644 index e4dc1168..00000000 --- a/core/maintenance/authenticate.go +++ /dev/null @@ -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) - } -} diff --git a/core/maintenance/client/client.go b/core/maintenance/client/client.go deleted file mode 100644 index 382ade84..00000000 --- a/core/maintenance/client/client.go +++ /dev/null @@ -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 - } - } - } -} diff --git a/core/maintenance/encoding/unmarshaler.go b/core/maintenance/encoding/unmarshaler.go deleted file mode 100644 index 04793bc8..00000000 --- a/core/maintenance/encoding/unmarshaler.go +++ /dev/null @@ -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) -} diff --git a/core/maintenance/version.go b/core/maintenance/version.go index fd16b8d2..8f14615b 100644 --- a/core/maintenance/version.go +++ b/core/maintenance/version.go @@ -19,34 +19,25 @@ const ( // CheckForUpdates checks for any available updates // and asks for the user if want to update now or not. func CheckForUpdates(ft bool) { - has := true - if ft { - has, ft = hasInternetConnection() - } - v := version.Acquire() updateAvailale := v.Compare(Version) == version.Smaller if updateAvailale { if confirmUpdate(v) { - canUpdate := (has && ft && ask()) || !has || !ft - if canUpdate { - installVersion() - } + installVersion() + return } } } func confirmUpdate(v version.Version) bool { - // on help? when asking for installing the new update - // and when answering "No". + // on help? when asking for installing the new update. ignoreUpdatesMsg := "Would you like to ignore future updates? Disable the version checker via:\napp.Run(..., iris.WithoutVersionChecker)" // if update available ask for update action. shouldUpdateNowMsg := - fmt.Sprintf("A new version is available online[%s < %s].\nRelease notes: %s.\nUpdate now?", - Version, v.String(), - v.ChangelogURL) + fmt.Sprintf("A new version is available online[%s > %s]. Type '?' for help.\nRelease notes: %s.\nUpdate now?", + v.String(), Version, v.ChangelogURL) var confirmUpdate bool survey.AskOne(&survey.Confirm{ diff --git a/deprecated.go b/deprecated.go index 744684ec..d44707b2 100644 --- a/deprecated.go +++ b/deprecated.go @@ -1,55 +1 @@ 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)) -}