Skip to content

Commit

Permalink
♻️ Refactor: Remove redundant nil check (#2584)
Browse files Browse the repository at this point in the history
From the Go docs:

  "If the map is nil, the number of iterations is 0." [1]

Therefore, an additional nil check for before the loop is unnecessary.

[1]: https://go.dev/ref/spec#For_range

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
  • Loading branch information
Juneezee authored Aug 17, 2023
1 parent 85d1f68 commit 242ff94
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions middleware/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ func New(config ...Config) fiber.Handler {
if len(e.cencoding) > 0 {
c.Response().Header.SetBytesV(fiber.HeaderContentEncoding, e.cencoding)
}
if e.headers != nil {
for k, v := range e.headers {
c.Response().Header.SetBytesV(k, v)
}
for k, v := range e.headers {
c.Response().Header.SetBytesV(k, v)
}
// Set Cache-Control header if enabled
if cfg.CacheControl {
Expand Down
6 changes: 2 additions & 4 deletions middleware/logger/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,8 @@ func createTagMap(cfg *Config) map[string]LogFunc {
},
}
// merge with custom tags from user
if cfg.CustomTags != nil {
for k, v := range cfg.CustomTags {
tagFunctions[k] = v
}
for k, v := range cfg.CustomTags {
tagFunctions[k] = v
}

return tagFunctions
Expand Down

1 comment on commit 242ff94

@ReneWerner87
Copy link
Member

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: 242ff94 Previous: 892b23b Ratio
Benchmark_AcquireCtx 2060 ns/op 1568 B/op 5 allocs/op 796.7 ns/op 1568 B/op 5 allocs/op 2.59

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

Please sign in to comment.