add a HISTORY note about the Context#ReadForm return error

Former-commit-id: ae423978262575d21d098f1ca2986de05d0cda49
This commit is contained in:
Gerasimos (Makis) Maropoulos 2018-10-18 20:56:41 +03:00
parent df85be52a4
commit 977b67dd47
2 changed files with 52 additions and 53 deletions

View File

@ -25,6 +25,7 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene
- `:int` parameter type **can accept negative numbers now**. - `:int` parameter type **can accept negative numbers now**.
- `app.Macros().String/Int/Uint64/Path...RegisterFunc` should be replaced to: `app.Macros().Get("string" or "int" or "uint64" or "path" when "path" is the ":path" parameter type).RegisterFunc`, because you can now add custom macros and parameter types as well, see [here](_examples/routing/macros). - `app.Macros().String/Int/Uint64/Path...RegisterFunc` should be replaced to: `app.Macros().Get("string" or "int" or "uint64" or "path" when "path" is the ":path" parameter type).RegisterFunc`, because you can now add custom macros and parameter types as well, see [here](_examples/routing/macros).
- `RegisterFunc("min", func(paramValue string) bool {...})` should be replaced to `RegisterFunc("min", func(paramValue <T>) bool {...})`, the `paramValue` argument is now stored in the exact type the macro's type evaluator inits it, i.e `uint64` or `int` and so on, therefore you don't have to convert the parameter value each time (this should make your handlers with macro functions activated even faster now) - `RegisterFunc("min", func(paramValue string) bool {...})` should be replaced to `RegisterFunc("min", func(paramValue <T>) bool {...})`, the `paramValue` argument is now stored in the exact type the macro's type evaluator inits it, i.e `uint64` or `int` and so on, therefore you don't have to convert the parameter value each time (this should make your handlers with macro functions activated even faster now)
- The `Context#ReadForm` will no longer return an error if it has no value to read from the request, we let those checks to the caller and validators as requested at: https://github.com/kataras/iris/issues/1095 by [@haritsfahreza](https://github.com/haritsfahreza)
## Routing ## Routing
@ -42,69 +43,69 @@ Code worths 1000 words, now it is possible to define your routes like this witho
package main package main
import ( import (
"github.com/kataras/iris" "github.com/kataras/iris"
"github.com/kataras/iris/context" "github.com/kataras/iris/context"
) )
func main() { func main() {
app := iris.New() app := iris.New()
// matches everyhing if nothing else found, // matches everyhing if nothing else found,
// so you can use it for custom 404 root-level/main pages! // so you can use it for custom 404 root-level/main pages!
app.Get("/{p:path}", func(ctx context.Context) { app.Get("/{p:path}", func(ctx context.Context) {
path := ctx.Params().Get("p") path := ctx.Params().Get("p")
// gives the path without the first "/". // gives the path without the first "/".
ctx.Writef("Site Custom 404 Error Message\nPage of: '%s' not found", path) ctx.Writef("Site Custom 404 Error Message\nPage of: '%s' not found", path)
}) })
app.Get("/", indexHandler) app.Get("/", indexHandler)
// request: http://localhost:8080/profile // request: http://localhost:8080/profile
// response: "Profile Index" // response: "Profile Index"
app.Get("/profile", func(ctx context.Context) { app.Get("/profile", func(ctx context.Context) {
ctx.Writef("Profile Index") ctx.Writef("Profile Index")
}) })
// request: http://localhost:8080/profile/kataras // request: http://localhost:8080/profile/kataras
// response: "Profile of username: 'kataras'" // response: "Profile of username: 'kataras'"
app.Get("/profile/{username}", func(ctx context.Context) { app.Get("/profile/{username}", func(ctx context.Context) {
username := ctx.Params().Get("username") username := ctx.Params().Get("username")
ctx.Writef("Profile of username: '%s'", username) ctx.Writef("Profile of username: '%s'", username)
}) })
// request: http://localhost:8080/profile/settings // request: http://localhost:8080/profile/settings
// response: "Profile personal settings" // response: "Profile personal settings"
app.Get("/profile/settings", func(ctx context.Context) { app.Get("/profile/settings", func(ctx context.Context) {
ctx.Writef("Profile personal settings") ctx.Writef("Profile personal settings")
}) })
// request: http://localhost:8080/profile/settings/security // request: http://localhost:8080/profile/settings/security
// response: "Profile personal security settings" // response: "Profile personal security settings"
app.Get("/profile/settings/security", func(ctx context.Context) { app.Get("/profile/settings/security", func(ctx context.Context) {
ctx.Writef("Profile personal security settings") ctx.Writef("Profile personal security settings")
}) })
// matches everyhing /profile/*somethng_here* // matches everyhing /profile/*somethng_here*
// if no other route matches the path semgnet after the // if no other route matches the path semgnet after the
// /profile or /profile/ // /profile or /profile/
// //
// So, you can use it for custom 404 profile pages // So, you can use it for custom 404 profile pages
// side-by-side to your root wildcard without issues! // side-by-side to your root wildcard without issues!
// For example: // For example:
// request: http://localhost:8080/profile/kataras/what // request: http://localhost:8080/profile/kataras/what
// response: // response:
// Profile Page Custom 404 Error Message // Profile Page Custom 404 Error Message
// Profile Page of: 'kataras/what' was unable to be found // Profile Page of: 'kataras/what' was unable to be found
app.Get("/profile/{p:path}", func(ctx context.Context) { app.Get("/profile/{p:path}", func(ctx context.Context) {
path := ctx.Params().Get("p") path := ctx.Params().Get("p")
ctx.Writef("Profile Page Custom 404 Error Message\nProfile Page of: '%s' not found", path) ctx.Writef("Profile Page Custom 404 Error Message\nProfile Page of: '%s' not found", path)
}) })
app.Run(iris.Addr(":8080")) app.Run(iris.Addr(":8080"))
} }
func indexHandler(ctx context.Context) { func indexHandler(ctx context.Context) {
ctx.HTML("This is the <strong>index page</strong>") ctx.HTML("This is the <strong>index page</strong>")
} }
``` ```

View File

@ -2864,12 +2864,10 @@ func (ctx *context) JSON(v interface{}, opts ...JSON) (n int, err error) {
options = opts[0] options = opts[0]
} }
optimize := ctx.shouldOptimize()
ctx.ContentType(ContentJSONHeaderValue) ctx.ContentType(ContentJSONHeaderValue)
if options.StreamingJSON { if options.StreamingJSON {
if optimize { if ctx.shouldOptimize() {
var jsoniterConfig = jsoniter.Config{ var jsoniterConfig = jsoniter.Config{
EscapeHTML: !options.UnescapeHTML, EscapeHTML: !options.UnescapeHTML,
IndentionStep: 4, IndentionStep: 4,
@ -2890,7 +2888,7 @@ func (ctx *context) JSON(v interface{}, opts ...JSON) (n int, err error) {
return ctx.writer.Written(), err return ctx.writer.Written(), err
} }
n, err = WriteJSON(ctx.writer, v, options, optimize) n, err = WriteJSON(ctx.writer, v, options, ctx.shouldOptimize())
if err != nil { if err != nil {
ctx.StatusCode(http.StatusInternalServerError) ctx.StatusCode(http.StatusInternalServerError)
return 0, err return 0, err