Skip to content

Commit

Permalink
Remove incorrect comments about context.Bind() and improve docs (#3028)
Browse files Browse the repository at this point in the history
  • Loading branch information
waynerv authored Jan 20, 2022
1 parent 1b28e2b commit 580e7da
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,10 @@ func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
return err
}

// Bind checks the Content-Type to select a binding engine automatically,
// Depending on the "Content-Type" header different bindings are used:
// Bind checks the Method and Content-Type to select a binding engine automatically,
// Depending on the "Content-Type" header different bindings are used, for example:
// "application/json" --> JSON binding
// "application/xml" --> XML binding
// otherwise --> returns an error.
// It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input.
// It decodes the json payload into the struct specified as a pointer.
// It writes a 400 error and sets Content-Type header "text/plain" in the response if input is not valid.
Expand Down Expand Up @@ -660,14 +659,13 @@ func (c *Context) MustBindWith(obj interface{}, b binding.Binding) error {
return nil
}

// ShouldBind checks the Content-Type to select a binding engine automatically,
// Depending on the "Content-Type" header different bindings are used:
// ShouldBind checks the Method and Content-Type to select a binding engine automatically,
// Depending on the "Content-Type" header different bindings are used, for example:
// "application/json" --> JSON binding
// "application/xml" --> XML binding
// otherwise --> returns an error
// It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input.
// It decodes the json payload into the struct specified as a pointer.
// Like c.Bind() but this method does not set the response status code to 400 and abort if the json is not valid.
// Like c.Bind() but this method does not set the response status code to 400 or abort if input is not valid.
func (c *Context) ShouldBind(obj interface{}) error {
b := binding.Default(c.Request.Method, c.ContentType())
return c.ShouldBindWith(obj, b)
Expand Down

0 comments on commit 580e7da

Please sign in to comment.