From 197df1ef64f9d7cc34e7e6d6681148edd5186572 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Sun, 24 Jan 2021 23:49:37 +0200 Subject: [PATCH] minor (see previous commit) --- .../request-body/read-json-stream/main.go | 28 +++++++++---------- _examples/view/fallback/main.go | 6 +--- aliases.go | 2 +- context/context.go | 2 +- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/_examples/request-body/read-json-stream/main.go b/_examples/request-body/read-json-stream/main.go index b203f1f1..dd9ac3a6 100644 --- a/_examples/request-body/read-json-stream/main.go +++ b/_examples/request-body/read-json-stream/main.go @@ -1,9 +1,6 @@ package main -import ( - "github.com/kataras/iris/v12" - "github.com/kataras/iris/v12/context" -) +import "github.com/kataras/iris/v12" func main() { app := iris.New() @@ -14,21 +11,21 @@ func main() { /* curl -L -X POST "http://localhost:8080/" \ -H 'Content-Type: application/json' \ - --data-raw '{"Username":"john"}' + --data-raw '{"username":"john"}' curl -L -X POST "http://localhost:8080/stream" \ -H 'Content-Type: application/json' \ - --data-raw '{"Username":"john"} - {"Username":"makis"} - {"Username":"george"} - {"Username":"michael"} + --data-raw '{"username":"john"} + {"username":"makis"} + {"username":"george"} + {"username":"michael"} ' If JSONReader.ArrayStream was true then you must provide an array of objects instead, e.g. - [{"Username":"john"}, - {"Username":"makis"}, - {"Username":"george"}, - {"Username":"michael"}] + [{"username":"john"}, + {"username":"makis"}, + {"username":"george"}, + {"username":"michael"}] */ @@ -44,6 +41,7 @@ func postIndex(ctx iris.Context) { err := ctx.ReadJSON(&u, iris.JSONReader{ // To throw an error on unknown request payload json fields. DisallowUnknownFields: true, + Optimize: true, }) if err != nil { ctx.StopWithError(iris.StatusBadRequest, err) @@ -58,7 +56,7 @@ func postIndex(ctx iris.Context) { func postIndexStream(ctx iris.Context) { var users []User - job := func(decode context.DecodeFunc) error { + job := func(decode iris.DecodeFunc) error { var u User if err := decode(&u); err != nil { return err @@ -70,7 +68,7 @@ func postIndexStream(ctx iris.Context) { return nil } - err := ctx.ReadJSONStream(job, context.JSONReader{ + err := ctx.ReadJSONStream(job, iris.JSONReader{ Optimize: true, DisallowUnknownFields: true, ArrayStream: false, diff --git a/_examples/view/fallback/main.go b/_examples/view/fallback/main.go index 3c722673..47837866 100644 --- a/_examples/view/fallback/main.go +++ b/_examples/view/fallback/main.go @@ -1,10 +1,6 @@ package main -import ( - "github.com/kataras/iris/v12" -) - -const defaultViewName = "fallback" +import "github.com/kataras/iris/v12" func main() { app := iris.New() diff --git a/aliases.go b/aliases.go index 3520fccd..37500a43 100644 --- a/aliases.go +++ b/aliases.go @@ -92,7 +92,7 @@ type ( JSON = context.JSON // JSONReader holds the JSON decode options of the `Context.ReadJSON, ReadBody` methods. // - // // It is an alias of the `context#JSONReader` type. + // It is an alias of the `context#JSONReader` type. JSONReader = context.JSONReader // JSONP the optional settings for JSONP renderer. // diff --git a/context/context.go b/context/context.go index 47f9c199..f447f633 100644 --- a/context/context.go +++ b/context/context.go @@ -2263,7 +2263,7 @@ type JSONReader struct { // Note(@kataras): struct instead of optional funcs to // [ // {"username":"john"}, // {"username": "makis"}, - // {"username": "george"}, + // {"username": "george"} // ] // Defaults to false: decodes a json object one by one, example: // {"username":"john"}