@@ -280,14 +280,15 @@ func (c *Context) Error(err error) *Error {
280280
281281// Set is used to store a new key/value pair exclusively for this context.
282282// It also lazy initializes c.Keys if it was not used previously.
283- func (c * Context ) Set (key any , value any ) {
283+ func (c * Context ) Set (key any , value any ) * Context {
284284 c .mu .Lock ()
285285 defer c .mu .Unlock ()
286286 if c .Keys == nil {
287287 c .Keys = make (map [any ]any )
288288 }
289289
290290 c .Keys [key ] = value
291+ return c
291292}
292293
293294// Get returns the value for the given key, ie: (value, true).
@@ -506,8 +507,9 @@ func (c *Context) Param(key string) string {
506507// Example Route: "/user/:id"
507508// AddParam("id", 1)
508509// Result: "/user/1"
509- func (c * Context ) AddParam (key , value string ) {
510+ func (c * Context ) AddParam (key , value string ) * Context {
510511 c .Params = append (c .Params , Param {Key : key , Value : value })
512+ return c
511513}
512514
513515// Query returns the keyed url query value if it exists,
@@ -1052,19 +1054,21 @@ func bodyAllowedForStatus(status int) bool {
10521054}
10531055
10541056// Status sets the HTTP response code.
1055- func (c * Context ) Status (code int ) {
1057+ func (c * Context ) Status (code int ) * Context {
10561058 c .Writer .WriteHeader (code )
1059+ return c
10571060}
10581061
10591062// Header is an intelligent shortcut for c.Writer.Header().Set(key, value).
10601063// It writes a header in the response.
10611064// If value == "", this method removes the header `c.Writer.Header().Del(key)`
1062- func (c * Context ) Header (key , value string ) {
1065+ func (c * Context ) Header (key , value string ) * Context {
10631066 if value == "" {
10641067 c .Writer .Header ().Del (key )
1065- return
1068+ return c
10661069 }
10671070 c .Writer .Header ().Set (key , value )
1071+ return c
10681072}
10691073
10701074// GetHeader returns value from request headers.
@@ -1081,14 +1085,15 @@ func (c *Context) GetRawData() ([]byte, error) {
10811085}
10821086
10831087// SetSameSite with cookie
1084- func (c * Context ) SetSameSite (samesite http.SameSite ) {
1088+ func (c * Context ) SetSameSite (samesite http.SameSite ) * Context {
10851089 c .sameSite = samesite
1090+ return c
10861091}
10871092
10881093// SetCookie adds a Set-Cookie header to the ResponseWriter's headers.
10891094// The provided cookie must have a valid Name. Invalid cookies may be
10901095// silently dropped.
1091- func (c * Context ) SetCookie (name , value string , maxAge int , path , domain string , secure , httpOnly bool ) {
1096+ func (c * Context ) SetCookie (name , value string , maxAge int , path , domain string , secure , httpOnly bool ) * Context {
10921097 if path == "" {
10931098 path = "/"
10941099 }
@@ -1102,19 +1107,21 @@ func (c *Context) SetCookie(name, value string, maxAge int, path, domain string,
11021107 Secure : secure ,
11031108 HttpOnly : httpOnly ,
11041109 })
1110+ return c
11051111}
11061112
11071113// SetCookieData adds a Set-Cookie header to the ResponseWriter's headers.
11081114// It accepts a pointer to http.Cookie structure for more flexibility in setting cookie attributes.
11091115// The provided cookie must have a valid Name. Invalid cookies may be silently dropped.
1110- func (c * Context ) SetCookieData (cookie * http.Cookie ) {
1116+ func (c * Context ) SetCookieData (cookie * http.Cookie ) * Context {
11111117 if cookie .Path == "" {
11121118 cookie .Path = "/"
11131119 }
11141120 if cookie .SameSite == http .SameSiteDefaultMode {
11151121 cookie .SameSite = c .sameSite
11161122 }
11171123 http .SetCookie (c .Writer , cookie )
1124+ return c
11181125}
11191126
11201127// Cookie returns the named cookie provided in the request or
@@ -1394,8 +1401,9 @@ func (c *Context) NegotiateFormat(offered ...string) string {
13941401}
13951402
13961403// SetAccepted sets Accept header data.
1397- func (c * Context ) SetAccepted (formats ... string ) {
1404+ func (c * Context ) SetAccepted (formats ... string ) * Context {
13981405 c .Accepted = formats
1406+ return c
13991407}
14001408
14011409/************************************/
0 commit comments