@@ -272,14 +272,15 @@ func (c *Context) Error(err error) *Error {
272272
273273// Set is used to store a new key/value pair exclusively for this context.
274274// It also lazy initializes c.Keys if it was not used previously.
275- func (c * Context ) Set (key any , value any ) {
275+ func (c * Context ) Set (key any , value any ) * Context {
276276 c .mu .Lock ()
277277 defer c .mu .Unlock ()
278278 if c .Keys == nil {
279279 c .Keys = make (map [any ]any )
280280 }
281281
282282 c .Keys [key ] = value
283+ return c
283284}
284285
285286// Get returns the value for the given key, ie: (value, true).
@@ -498,8 +499,9 @@ func (c *Context) Param(key string) string {
498499// Example Route: "/user/:id"
499500// AddParam("id", 1)
500501// Result: "/user/1"
501- func (c * Context ) AddParam (key , value string ) {
502+ func (c * Context ) AddParam (key , value string ) * Context {
502503 c .Params = append (c .Params , Param {Key : key , Value : value })
504+ return c
503505}
504506
505507// Query returns the keyed url query value if it exists,
@@ -1014,19 +1016,21 @@ func bodyAllowedForStatus(status int) bool {
10141016}
10151017
10161018// Status sets the HTTP response code.
1017- func (c * Context ) Status (code int ) {
1019+ func (c * Context ) Status (code int ) * Context {
10181020 c .Writer .WriteHeader (code )
1021+ return c
10191022}
10201023
10211024// Header is an intelligent shortcut for c.Writer.Header().Set(key, value).
10221025// It writes a header in the response.
10231026// If value == "", this method removes the header `c.Writer.Header().Del(key)`
1024- func (c * Context ) Header (key , value string ) {
1027+ func (c * Context ) Header (key , value string ) * Context {
10251028 if value == "" {
10261029 c .Writer .Header ().Del (key )
1027- return
1030+ return c
10281031 }
10291032 c .Writer .Header ().Set (key , value )
1033+ return c
10301034}
10311035
10321036// GetHeader returns value from request headers.
@@ -1043,14 +1047,15 @@ func (c *Context) GetRawData() ([]byte, error) {
10431047}
10441048
10451049// SetSameSite with cookie
1046- func (c * Context ) SetSameSite (samesite http.SameSite ) {
1050+ func (c * Context ) SetSameSite (samesite http.SameSite ) * Context {
10471051 c .sameSite = samesite
1052+ return c
10481053}
10491054
10501055// SetCookie adds a Set-Cookie header to the ResponseWriter's headers.
10511056// The provided cookie must have a valid Name. Invalid cookies may be
10521057// silently dropped.
1053- func (c * Context ) SetCookie (name , value string , maxAge int , path , domain string , secure , httpOnly bool ) {
1058+ func (c * Context ) SetCookie (name , value string , maxAge int , path , domain string , secure , httpOnly bool ) * Context {
10541059 if path == "" {
10551060 path = "/"
10561061 }
@@ -1064,19 +1069,21 @@ func (c *Context) SetCookie(name, value string, maxAge int, path, domain string,
10641069 Secure : secure ,
10651070 HttpOnly : httpOnly ,
10661071 })
1072+ return c
10671073}
10681074
10691075// SetCookieData adds a Set-Cookie header to the ResponseWriter's headers.
10701076// It accepts a pointer to http.Cookie structure for more flexibility in setting cookie attributes.
10711077// The provided cookie must have a valid Name. Invalid cookies may be silently dropped.
1072- func (c * Context ) SetCookieData (cookie * http.Cookie ) {
1078+ func (c * Context ) SetCookieData (cookie * http.Cookie ) * Context {
10731079 if cookie .Path == "" {
10741080 cookie .Path = "/"
10751081 }
10761082 if cookie .SameSite == http .SameSiteDefaultMode {
10771083 cookie .SameSite = c .sameSite
10781084 }
10791085 http .SetCookie (c .Writer , cookie )
1086+ return c
10801087}
10811088
10821089// Cookie returns the named cookie provided in the request or
@@ -1356,8 +1363,9 @@ func (c *Context) NegotiateFormat(offered ...string) string {
13561363}
13571364
13581365// SetAccepted sets Accept header data.
1359- func (c * Context ) SetAccepted (formats ... string ) {
1366+ func (c * Context ) SetAccepted (formats ... string ) * Context {
13601367 c .Accepted = formats
1368+ return c
13611369}
13621370
13631371/************************************/
0 commit comments