@@ -153,9 +153,10 @@ func (c *Context) Handler() HandlerFunc {
153
153
154
154
// FullPath returns a matched route full path. For not found routes
155
155
// returns an empty string.
156
- // router.GET("/user/:id", func(c *gin.Context) {
157
- // c.FullPath() == "/user/:id" // true
158
- // })
156
+ //
157
+ // router.GET("/user/:id", func(c *gin.Context) {
158
+ // c.FullPath() == "/user/:id" // true
159
+ // })
159
160
func (c * Context ) FullPath () string {
160
161
return c .fullPath
161
162
}
@@ -382,10 +383,11 @@ func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)
382
383
383
384
// Param returns the value of the URL param.
384
385
// It is a shortcut for c.Params.ByName(key)
385
- // router.GET("/user/:id", func(c *gin.Context) {
386
- // // a GET request to /user/john
387
- // id := c.Param("id") // id == "john"
388
- // })
386
+ //
387
+ // router.GET("/user/:id", func(c *gin.Context) {
388
+ // // a GET request to /user/john
389
+ // id := c.Param("id") // id == "john"
390
+ // })
389
391
func (c * Context ) Param (key string ) string {
390
392
return c .Params .ByName (key )
391
393
}
@@ -402,11 +404,12 @@ func (c *Context) AddParam(key, value string) {
402
404
// Query returns the keyed url query value if it exists,
403
405
// otherwise it returns an empty string `("")`.
404
406
// It is shortcut for `c.Request.URL.Query().Get(key)`
405
- // GET /path?id=1234&name=Manu&value=
406
- // c.Query("id") == "1234"
407
- // c.Query("name") == "Manu"
408
- // c.Query("value") == ""
409
- // c.Query("wtf") == ""
407
+ //
408
+ // GET /path?id=1234&name=Manu&value=
409
+ // c.Query("id") == "1234"
410
+ // c.Query("name") == "Manu"
411
+ // c.Query("value") == ""
412
+ // c.Query("wtf") == ""
410
413
func (c * Context ) Query (key string ) (value string ) {
411
414
value , _ = c .GetQuery (key )
412
415
return
@@ -415,10 +418,11 @@ func (c *Context) Query(key string) (value string) {
415
418
// DefaultQuery returns the keyed url query value if it exists,
416
419
// otherwise it returns the specified defaultValue string.
417
420
// See: Query() and GetQuery() for further information.
418
- // GET /?name=Manu&lastname=
419
- // c.DefaultQuery("name", "unknown") == "Manu"
420
- // c.DefaultQuery("id", "none") == "none"
421
- // c.DefaultQuery("lastname", "none") == ""
421
+ //
422
+ // GET /?name=Manu&lastname=
423
+ // c.DefaultQuery("name", "unknown") == "Manu"
424
+ // c.DefaultQuery("id", "none") == "none"
425
+ // c.DefaultQuery("lastname", "none") == ""
422
426
func (c * Context ) DefaultQuery (key , defaultValue string ) string {
423
427
if value , ok := c .GetQuery (key ); ok {
424
428
return value
@@ -430,10 +434,11 @@ func (c *Context) DefaultQuery(key, defaultValue string) string {
430
434
// if it exists `(value, true)` (even when the value is an empty string),
431
435
// otherwise it returns `("", false)`.
432
436
// It is shortcut for `c.Request.URL.Query().Get(key)`
433
- // GET /?name=Manu&lastname=
434
- // ("Manu", true) == c.GetQuery("name")
435
- // ("", false) == c.GetQuery("id")
436
- // ("", true) == c.GetQuery("lastname")
437
+ //
438
+ // GET /?name=Manu&lastname=
439
+ // ("Manu", true) == c.GetQuery("name")
440
+ // ("", false) == c.GetQuery("id")
441
+ // ("", true) == c.GetQuery("lastname")
437
442
func (c * Context ) GetQuery (key string ) (string , bool ) {
438
443
if values , ok := c .GetQueryArray (key ); ok {
439
444
return values [0 ], ok
@@ -500,9 +505,10 @@ func (c *Context) DefaultPostForm(key, defaultValue string) string {
500
505
// form or multipart form when it exists `(value, true)` (even when the value is an empty string),
501
506
// otherwise it returns ("", false).
502
507
// For example, during a PATCH request to update the user's email:
503
- // [email protected] --> ("[email protected] ", true) := GetPostForm("email") // set email to "[email protected] "
504
- // email= --> ("", true) := GetPostForm("email") // set email to ""
505
- // --> ("", false) := GetPostForm("email") // do nothing with email
508
+ //
509
+ // [email protected] --> ("[email protected] ", true) := GetPostForm("email") // set email to "[email protected] "
510
+ // email= --> ("", true) := GetPostForm("email") // set email to ""
511
+ // --> ("", false) := GetPostForm("email") // do nothing with email
506
512
func (c * Context ) GetPostForm (key string ) (string , bool ) {
507
513
if values , ok := c .GetPostFormArray (key ); ok {
508
514
return values [0 ], ok
@@ -607,8 +613,10 @@ func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
607
613
608
614
// Bind checks the Method and Content-Type to select a binding engine automatically,
609
615
// Depending on the "Content-Type" header different bindings are used, for example:
610
- // "application/json" --> JSON binding
611
- // "application/xml" --> XML binding
616
+ //
617
+ // "application/json" --> JSON binding
618
+ // "application/xml" --> XML binding
619
+ //
612
620
// It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input.
613
621
// It decodes the json payload into the struct specified as a pointer.
614
622
// It writes a 400 error and sets Content-Type header "text/plain" in the response if input is not valid.
@@ -651,7 +659,7 @@ func (c *Context) BindHeader(obj any) error {
651
659
// It will abort the request with HTTP 400 if any error occurs.
652
660
func (c * Context ) BindUri (obj any ) error {
653
661
if err := c .ShouldBindUri (obj ); err != nil {
654
- c .AbortWithError (http .StatusBadRequest , err ).SetType (ErrorTypeBind ) // nolint: errcheck
662
+ c .AbortWithError (http .StatusBadRequest , err ).SetType (ErrorTypeBind ) //nolint: errcheck
655
663
return err
656
664
}
657
665
return nil
@@ -662,16 +670,18 @@ func (c *Context) BindUri(obj any) error {
662
670
// See the binding package.
663
671
func (c * Context ) MustBindWith (obj any , b binding.Binding ) error {
664
672
if err := c .ShouldBindWith (obj , b ); err != nil {
665
- c .AbortWithError (http .StatusBadRequest , err ).SetType (ErrorTypeBind ) // nolint: errcheck
673
+ c .AbortWithError (http .StatusBadRequest , err ).SetType (ErrorTypeBind ) //nolint: errcheck
666
674
return err
667
675
}
668
676
return nil
669
677
}
670
678
671
679
// ShouldBind checks the Method and Content-Type to select a binding engine automatically,
672
680
// Depending on the "Content-Type" header different bindings are used, for example:
673
- // "application/json" --> JSON binding
674
- // "application/xml" --> XML binding
681
+ //
682
+ // "application/json" --> JSON binding
683
+ // "application/xml" --> XML binding
684
+ //
675
685
// It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input.
676
686
// It decodes the json payload into the struct specified as a pointer.
677
687
// Like c.Bind() but this method does not set the response status code to 400 or abort if input is not valid.
@@ -1112,7 +1122,7 @@ func (c *Context) Negotiate(code int, config Negotiate) {
1112
1122
c .TOML (code , data )
1113
1123
1114
1124
default :
1115
- c .AbortWithError (http .StatusNotAcceptable , errors .New ("the accepted formats are not offered by the server" )) // nolint: errcheck
1125
+ c .AbortWithError (http .StatusNotAcceptable , errors .New ("the accepted formats are not offered by the server" )) //nolint: errcheck
1116
1126
}
1117
1127
}
1118
1128
0 commit comments