mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
minor (see previous commit)
This commit is contained in:
parent
53b3ade7e0
commit
197df1ef64
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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.
|
||||
//
|
||||
|
|
|
@ -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"}
|
||||
|
|
Loading…
Reference in New Issue
Block a user