-
Notifications
You must be signed in to change notification settings - Fork 1.4k
JSON Parameter binding #1173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON Parameter binding #1173
Conversation
e2bf0f4
to
5cbae9e
Compare
…on to not store validation state via a cookie, since with a json request/response no redirect is required and therefor no persistent data is required. Also renamed local variable error to err so no package conflict error will occur
params.go
Outdated
@@ -31,6 +32,7 @@ type Params struct { | |||
|
|||
Files map[string][]*multipart.FileHeader // Files uploaded in a multipart form | |||
tmpFiles []*os.File // Temp files used during the request. | |||
Json []byte // JSON data from request body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON
params.go
Outdated
ERROR.Println("Failed to ready request body bytes",err) | ||
} | ||
} else { | ||
INFO.Println("Json post received with empty body") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON
} | ||
hasCookie := (err != http.ErrNoCookie) | ||
// If json request, we shall assume json response is intended, | ||
// as such no validation cookies should be tied response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tied to the response
params.go
Outdated
case "application/json": | ||
fallthrough | ||
case "text/json": | ||
if req.Body!=nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WORD != WORD
keep: false, | ||
} | ||
hasCookie := (err != http.ErrNoCookie) | ||
// If json request, we shall assume json response is intended, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON
Updated params so that Params.Bind() does not blindly bind json data Added Params.BindJSON() to provide JSON bind functionality
Automatic JSON binding to struct in parameters, also changed validation to not store validation state via a cookie, since with a json request/response no redirect is required and therefor no persistent data is required.
Also renamed local variable error to err so no package conflict error will occur