From ae4f5b3b909a3817235cb9eaad56fd5240575d41 Mon Sep 17 00:00:00 2001 From: Leon Clark Date: Thu, 14 Mar 2024 18:46:15 -0700 Subject: [PATCH] lint fixes --- errs/cause.go | 4 ++-- errs/stack.go | 2 +- httplog/request.go | 8 +++++--- httputil/rapidoc.go | 2 +- httputil/wrap_writer.go | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/errs/cause.go b/errs/cause.go index f477e09..ae50a92 100644 --- a/errs/cause.go +++ b/errs/cause.go @@ -7,12 +7,12 @@ package errs // This supports both Go 1.13+ style `UnWrap` and pkg.errors style // `Cause` chaining. func Cause(err error) error { - u, ok := err.(interface{ Unwrap() error }) //nolint:errorlint // false positive + u, ok := err.(interface{ Unwrap() error }) if ok { return u.Unwrap() //nolint:wrapcheck // defeats the whole point } - c, ok := err.(interface{ Cause() error }) //nolint:errorlint // false positive + c, ok := err.(interface{ Cause() error }) if ok { return c.Cause() //nolint:wrapcheck // defeats the whole point } diff --git a/errs/stack.go b/errs/stack.go index 5e53486..c08077c 100644 --- a/errs/stack.go +++ b/errs/stack.go @@ -89,7 +89,7 @@ func (f Frame) String() string { func ExtractStackFrame(err error) []Frame { type stackTracer interface{ StackTrace() []uintptr } - stacker, ok := err.(stackTracer) //nolint:errorlint // false positive + stacker, ok := err.(stackTracer) if !ok { return nil } diff --git a/httplog/request.go b/httplog/request.go index 2926892..b95f326 100644 --- a/httplog/request.go +++ b/httplog/request.go @@ -74,6 +74,7 @@ func RequestLogger(shouldLog FnShouldLog) func(http.Handler) http.Handler { //no } var responseBuffer *bytes.Buffer + wrappedWriter := httputil.WrapWriter(w) if logResponse { @@ -112,15 +113,16 @@ func RequestLogger(shouldLog FnShouldLog) func(http.Handler) http.Handler { //no } logger := l.Logger() + var event *zerolog.Event switch { case status >= http.StatusInternalServerError: - event = logger.Error() //nolint + event = logger.Error() case status >= http.StatusBadRequest: - event = logger.Warn() //nolint + event = logger.Warn() default: - event = logger.Info() //nolint + event = logger.Info() } event.Msgf("%d %s %s", status, r.Method, r.URL) diff --git a/httputil/rapidoc.go b/httputil/rapidoc.go index 82152c0..c697e22 100644 --- a/httputil/rapidoc.go +++ b/httputil/rapidoc.go @@ -54,7 +54,7 @@ func RapiDoc(opts RapiDocOpts) func(w http.ResponseWriter, r *http.Request) { _ = tmpl.Execute(buf, opts) b := buf.Bytes() - return func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") _, _ = w.Write(b) diff --git a/httputil/wrap_writer.go b/httputil/wrap_writer.go index 54af9a4..1eebbe1 100644 --- a/httputil/wrap_writer.go +++ b/httputil/wrap_writer.go @@ -2,7 +2,7 @@ package httputil import ( "bufio" - "fmt" + "errors" "io" "net" "net/http" @@ -122,7 +122,7 @@ func (f *fancyWriter) Flush() { f.basicWriter.Flush() } -var ErrUnsupported = fmt.Errorf("not implemented") +var ErrUnsupported = errors.New("not implemented") func (f *fancyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { hj, ok := f.basicWriter.ResponseWriter.(http.Hijacker)