|
|
|
@@ -153,6 +153,7 @@ func (c *Context) Handler() HandlerFunc {
|
|
|
|
|
|
|
|
|
|
// FullPath returns a matched route full path. For not found routes
|
|
|
|
|
// returns an empty string.
|
|
|
|
|
//
|
|
|
|
|
// router.GET("/user/:id", func(c *gin.Context) {
|
|
|
|
|
// c.FullPath() == "/user/:id" // true
|
|
|
|
|
// })
|
|
|
|
@@ -382,6 +383,7 @@ func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)
|
|
|
|
|
|
|
|
|
|
// Param returns the value of the URL param.
|
|
|
|
|
// It is a shortcut for c.Params.ByName(key)
|
|
|
|
|
//
|
|
|
|
|
// router.GET("/user/:id", func(c *gin.Context) {
|
|
|
|
|
// // a GET request to /user/john
|
|
|
|
|
// id := c.Param("id") // id == "john"
|
|
|
|
@@ -402,6 +404,7 @@ func (c *Context) AddParam(key, value string) {
|
|
|
|
|
// Query returns the keyed url query value if it exists,
|
|
|
|
|
// otherwise it returns an empty string `("")`.
|
|
|
|
|
// It is shortcut for `c.Request.URL.Query().Get(key)`
|
|
|
|
|
//
|
|
|
|
|
// GET /path?id=1234&name=Manu&value=
|
|
|
|
|
// c.Query("id") == "1234"
|
|
|
|
|
// c.Query("name") == "Manu"
|
|
|
|
@@ -415,6 +418,7 @@ func (c *Context) Query(key string) (value string) {
|
|
|
|
|
// DefaultQuery returns the keyed url query value if it exists,
|
|
|
|
|
// otherwise it returns the specified defaultValue string.
|
|
|
|
|
// See: Query() and GetQuery() for further information.
|
|
|
|
|
//
|
|
|
|
|
// GET /?name=Manu&lastname=
|
|
|
|
|
// c.DefaultQuery("name", "unknown") == "Manu"
|
|
|
|
|
// c.DefaultQuery("id", "none") == "none"
|
|
|
|
@@ -430,6 +434,7 @@ func (c *Context) DefaultQuery(key, defaultValue string) string {
|
|
|
|
|
// if it exists `(value, true)` (even when the value is an empty string),
|
|
|
|
|
// otherwise it returns `("", false)`.
|
|
|
|
|
// It is shortcut for `c.Request.URL.Query().Get(key)`
|
|
|
|
|
//
|
|
|
|
|
// GET /?name=Manu&lastname=
|
|
|
|
|
// ("Manu", true) == c.GetQuery("name")
|
|
|
|
|
// ("", false) == c.GetQuery("id")
|
|
|
|
@@ -500,6 +505,7 @@ func (c *Context) DefaultPostForm(key, defaultValue string) string {
|
|
|
|
|
// form or multipart form when it exists `(value, true)` (even when the value is an empty string),
|
|
|
|
|
// otherwise it returns ("", false).
|
|
|
|
|
// For example, during a PATCH request to update the user's email:
|
|
|
|
|
//
|
|
|
|
|
// email=mail@example.com --> ("mail@example.com", true) := GetPostForm("email") // set email to "mail@example.com"
|
|
|
|
|
// email= --> ("", true) := GetPostForm("email") // set email to ""
|
|
|
|
|
// --> ("", false) := GetPostForm("email") // do nothing with email
|
|
|
|
@@ -607,8 +613,10 @@ func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
@@ -670,8 +678,10 @@ func (c *Context) MustBindWith(obj any, b binding.Binding) error {
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
//
|
|
|
|
|
// 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 or abort if input is not valid.
|
|
|
|
|