Skip to content

Commit

Permalink
Merge pull request #541 from Fenny/master
Browse files Browse the repository at this point in the history
Add default value support
  • Loading branch information
Fenny authored Jul 4, 2020
2 parents 88d7425 + 29c4703 commit c39a12c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,10 @@ func (ctx *Ctx) Cookie(cookie *Cookie) {
}

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

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

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

1 comment on commit c39a12c

@Fenny
Copy link
Member Author

@Fenny Fenny commented on c39a12c Jul 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: c39a12c Previous: 88d7425 Ratio
Benchmark_Ctx_Params 112 ns/op 0 B/op 0 allocs/op 54.9 ns/op 0 B/op 0 allocs/op 2.04

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.