Skip to content

Commit c39a12c

Browse files
authored
Merge pull request #541 from Fenny/master
Add default value support
2 parents 88d7425 + 29c4703 commit c39a12c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ctx.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,10 @@ func (ctx *Ctx) Cookie(cookie *Cookie) {
310310
}
311311

312312
// Cookies is used for getting a cookie value by key
313+
// Defaults to empty string "" if the cookie doesn't exist.
314+
// If a default value is given, it will return that value if the cookie doesn't exist.
313315
// Returned value is only valid within the handler. Do not store any references.
314-
// Make copies or use the Immutable setting instead.
316+
// Make copies or use the Immutable setting to use the value outside the Handler.
315317
func (ctx *Ctx) Cookies(key string, defaultValue ...string) string {
316318
return defaultString(getString(ctx.Fasthttp.Request.Header.Cookie(key)), defaultValue)
317319
}
@@ -628,7 +630,10 @@ func (ctx *Ctx) OriginalURL() string {
628630
}
629631

630632
// Params is used to get the route parameters.
631-
// Defaults to empty string "", if the param doesn't exist.
633+
// Defaults to empty string "" if the param doesn't exist.
634+
// If a default value is given, it will return that value if the param doesn't exist.
635+
// Returned value is only valid within the handler. Do not store any references.
636+
// Make copies or use the Immutable setting to use the value outside the Handler.
632637
func (ctx *Ctx) Params(key string, defaultValue ...string) string {
633638
for i := range ctx.route.routeParams {
634639
if len(key) != len(ctx.route.routeParams[i]) {
@@ -685,8 +690,10 @@ func (ctx *Ctx) Protocol() string {
685690
}
686691

687692
// Query returns the query string parameter in the url.
693+
// Defaults to empty string "" if the query doesn't exist.
694+
// If a default value is given, it will return that value if the query doesn't exist.
688695
// Returned value is only valid within the handler. Do not store any references.
689-
// Make copies or use the Immutable setting instead.
696+
// Make copies or use the Immutable setting to use the value outside the Handler.
690697
func (ctx *Ctx) Query(key string, defaultValue ...string) string {
691698
return defaultString(getString(ctx.Fasthttp.QueryArgs().Peek(key)), defaultValue)
692699
}

0 commit comments

Comments
 (0)