From 6a449876e933b912f678d0c838d6e20a9ddde8ba Mon Sep 17 00:00:00 2001 From: Eng Zer Jun Date: Tue, 22 Aug 2023 01:12:22 +0800 Subject: [PATCH] Remove redundant nil check (#2194) 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 --- context/response_recorder.go | 10 ++++------ context/response_writer.go | 10 ++++------ view/jet.go | 6 ++---- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/context/response_recorder.go b/context/response_recorder.go index db3241ee..850b6781 100644 --- a/context/response_recorder.go +++ b/context/response_recorder.go @@ -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) } } } diff --git a/context/response_writer.go b/context/response_writer.go index 12dd7e8a..18f88ea3 100644 --- a/context/response_writer.go +++ b/context/response_writer.go @@ -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) } } } diff --git a/view/jet.go b/view/jet.go index 3c0d7edc..5fb8f719 100644 --- a/view/jet.go +++ b/view/jet.go @@ -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()