Skip to content

Commit

Permalink
Remove redundant nil check (#2194)
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 <[email protected]>
  • Loading branch information
Juneezee authored Aug 21, 2023
1 parent 9f53d15 commit 6a44987
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
10 changes: 4 additions & 6 deletions context/response_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,10 @@ func (w *ResponseRecorder) CopyTo(res ResponseWriter) {
}

// append the headers
if w.headers != nil {
for k, values := range w.headers {
for _, v := range values {
if to.headers.Get(v) == "" {
to.headers.Add(k, v)
}
for k, values := range w.headers {
for _, v := range values {
if to.headers.Get(v) == "" {
to.headers.Add(k, v)
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions context/response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,10 @@ func (w *responseWriter) CopyTo(to ResponseWriter) {
}

// append the headers
if w.Header() != nil {
for k, values := range w.Header() {
for _, v := range values {
if to.Header().Get(v) == "" {
to.Header().Add(k, v)
}
for k, values := range w.Header() {
for _, v := range values {
if to.Header().Get(v) == "" {
to.Header().Add(k, v)
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions view/jet.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,8 @@ func (s *JetEngine) initSet() {
}

s.Set = jet.NewSet(s.loader, opts...)
if s.vars != nil {
for key, value := range s.vars {
s.Set.AddGlobal(key, value)
}
for key, value := range s.vars {
s.Set.AddGlobal(key, value)
}
}
s.mu.Unlock()
Expand Down

0 comments on commit 6a44987

Please sign in to comment.