mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
minor (see previous commit)
This commit is contained in:
parent
53b3ade7e0
commit
197df1ef64
|
@ -1,9 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "github.com/kataras/iris/v12"
|
||||||
"github.com/kataras/iris/v12"
|
|
||||||
"github.com/kataras/iris/v12/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
|
@ -14,21 +11,21 @@ func main() {
|
||||||
/*
|
/*
|
||||||
curl -L -X POST "http://localhost:8080/" \
|
curl -L -X POST "http://localhost:8080/" \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
--data-raw '{"Username":"john"}'
|
--data-raw '{"username":"john"}'
|
||||||
|
|
||||||
curl -L -X POST "http://localhost:8080/stream" \
|
curl -L -X POST "http://localhost:8080/stream" \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
--data-raw '{"Username":"john"}
|
--data-raw '{"username":"john"}
|
||||||
{"Username":"makis"}
|
{"username":"makis"}
|
||||||
{"Username":"george"}
|
{"username":"george"}
|
||||||
{"Username":"michael"}
|
{"username":"michael"}
|
||||||
'
|
'
|
||||||
|
|
||||||
If JSONReader.ArrayStream was true then you must provide an array of objects instead, e.g.
|
If JSONReader.ArrayStream was true then you must provide an array of objects instead, e.g.
|
||||||
[{"Username":"john"},
|
[{"username":"john"},
|
||||||
{"Username":"makis"},
|
{"username":"makis"},
|
||||||
{"Username":"george"},
|
{"username":"george"},
|
||||||
{"Username":"michael"}]
|
{"username":"michael"}]
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -44,6 +41,7 @@ func postIndex(ctx iris.Context) {
|
||||||
err := ctx.ReadJSON(&u, iris.JSONReader{
|
err := ctx.ReadJSON(&u, iris.JSONReader{
|
||||||
// To throw an error on unknown request payload json fields.
|
// To throw an error on unknown request payload json fields.
|
||||||
DisallowUnknownFields: true,
|
DisallowUnknownFields: true,
|
||||||
|
Optimize: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.StopWithError(iris.StatusBadRequest, err)
|
ctx.StopWithError(iris.StatusBadRequest, err)
|
||||||
|
@ -58,7 +56,7 @@ func postIndex(ctx iris.Context) {
|
||||||
|
|
||||||
func postIndexStream(ctx iris.Context) {
|
func postIndexStream(ctx iris.Context) {
|
||||||
var users []User
|
var users []User
|
||||||
job := func(decode context.DecodeFunc) error {
|
job := func(decode iris.DecodeFunc) error {
|
||||||
var u User
|
var u User
|
||||||
if err := decode(&u); err != nil {
|
if err := decode(&u); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -70,7 +68,7 @@ func postIndexStream(ctx iris.Context) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := ctx.ReadJSONStream(job, context.JSONReader{
|
err := ctx.ReadJSONStream(job, iris.JSONReader{
|
||||||
Optimize: true,
|
Optimize: true,
|
||||||
DisallowUnknownFields: true,
|
DisallowUnknownFields: true,
|
||||||
ArrayStream: false,
|
ArrayStream: false,
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "github.com/kataras/iris/v12"
|
||||||
"github.com/kataras/iris/v12"
|
|
||||||
)
|
|
||||||
|
|
||||||
const defaultViewName = "fallback"
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
|
|
|
@ -92,7 +92,7 @@ type (
|
||||||
JSON = context.JSON
|
JSON = context.JSON
|
||||||
// JSONReader holds the JSON decode options of the `Context.ReadJSON, ReadBody` methods.
|
// 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
|
JSONReader = context.JSONReader
|
||||||
// JSONP the optional settings for JSONP renderer.
|
// 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":"john"},
|
||||||
// {"username": "makis"},
|
// {"username": "makis"},
|
||||||
// {"username": "george"},
|
// {"username": "george"}
|
||||||
// ]
|
// ]
|
||||||
// Defaults to false: decodes a json object one by one, example:
|
// Defaults to false: decodes a json object one by one, example:
|
||||||
// {"username":"john"}
|
// {"username":"john"}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user