From 3f5e5619b7744d8a893cbea6833ac54ee4d62d50 Mon Sep 17 00:00:00 2001 From: Ujjwal Kanth Date: Tue, 3 Oct 2023 05:52:46 +0000 Subject: [PATCH] fix: ci lint issues --- .github/workflows/go.yml | 2 +- transport/http/filter_panic.go | 20 ++++++++++---------- transport/http/filters.go | 2 +- transport/http/response.go | 5 ++--- transport/http/transport_config.go | 12 ++++++++---- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ca2a5a2..21aa7a7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -81,6 +81,6 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.45.2 + version: v1.54.2 working-directory: . # args: -D varnamelen diff --git a/transport/http/filter_panic.go b/transport/http/filter_panic.go index 5be9792..f28cb27 100644 --- a/transport/http/filter_panic.go +++ b/transport/http/filter_panic.go @@ -82,7 +82,7 @@ func newTextPanicFormatter() PanicFormatter { return &textPanicFormatter{} } // htmlFormatter func (html *htmlPanicFormatter) Format(w http.ResponseWriter, r *http.Request, info *PanicInformation) { w.Header().Set("Content-Type", "text/html; charset=utf-8") - html.template.Execute(w, info) + _ = html.template.Execute(w, info) } func newHtmlPanicFormatter() PanicFormatter { @@ -152,19 +152,19 @@ func (rec *recovery) HandlerFunc( } } -func withTextFormatter() RecoveryOption { +func WithTextFormatter() RecoveryOption { return func(r *recovery) { r.formatter = newTextPanicFormatter() } } -func withHTMLFormatter() RecoveryOption { +func WithHTMLFormatter() RecoveryOption { return func(r *recovery) { r.formatter = newHtmlPanicFormatter() } } -func withCustomFormatter(formatter PanicFormatter) RecoveryOption { +func WithCustomFormatter(formatter PanicFormatter) RecoveryOption { return func(r *recovery) { r.formatter = formatter } } -func withStack(stackSize int, stackOtherGoroutines bool) RecoveryOption { +func WithStack(stackSize int, stackOtherGoroutines bool) RecoveryOption { return func(r *recovery) { r.returnStack = true r.stackSize = stackSize @@ -172,18 +172,18 @@ func withStack(stackSize int, stackOtherGoroutines bool) RecoveryOption { } } -func withFormatterType(formatterType PanicFormatterType) RecoveryOption { +func WithFormatterType(formatterType PanicFormatterType) RecoveryOption { return func(r *recovery) { switch formatterType { case TextPanicFormatter: - withTextFormatter()(r) + WithTextFormatter()(r) case HTMLPanicFormatter: - withHTMLFormatter()(r) + WithHTMLFormatter()(r) } } } -func withoutStack() RecoveryOption { +func WithoutStack() RecoveryOption { return func(r *recovery) { r.returnStack = false; r.stackOthers = false } } @@ -210,7 +210,7 @@ func NewRecovery( return r } -func panicRecoveryFilter(logger log.Logger, options ...RecoveryOption) Filter { +func PanicRecoveryFilter(logger log.Logger, options ...RecoveryOption) Filter { recovery := NewRecovery(logger, options...) return func(next http.Handler) http.Handler { diff --git a/transport/http/filters.go b/transport/http/filters.go index 24ac214..839e3d8 100644 --- a/transport/http/filters.go +++ b/transport/http/filters.go @@ -84,7 +84,7 @@ func heartbeatFilter(name string, heartbeats []string) Filter { if ok { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - w.Write([]byte(message)) + _, _ = w.Write([]byte(message)) return } } diff --git a/transport/http/response.go b/transport/http/response.go index 3692b48..88b6475 100644 --- a/transport/http/response.go +++ b/transport/http/response.go @@ -3,7 +3,6 @@ package http import ( "bytes" "io" - "io/ioutil" net_http "net/http" ) @@ -15,7 +14,7 @@ type ResponseOption func(*net_http.Response) // with Bytes data func ResponseWithBytes(bt []byte) ResponseOption { return func(res *net_http.Response) { - res.Body = ioutil.NopCloser(bytes.NewReader(bt)) + res.Body = io.NopCloser(bytes.NewReader(bt)) } } @@ -32,7 +31,7 @@ func ResponseWithCode(code int) ResponseOption { // of the response with a custom reader func ResponseWithReader(reader io.Reader) ResponseOption { return func(res *net_http.Response) { - res.Body = ioutil.NopCloser(reader) + res.Body = io.NopCloser(reader) } } diff --git a/transport/http/transport_config.go b/transport/http/transport_config.go index 80b6edd..9ef2f69 100644 --- a/transport/http/transport_config.go +++ b/transport/http/transport_config.go @@ -66,10 +66,10 @@ func (c *config) filters() []Filter { // default filters available by default to all routes filters := []Filter{ closerFilter(), // closes the request - panicRecoveryFilter( // handles panic + PanicRecoveryFilter( // handles panic c.logger, - withCustomFormatter(c.panicFormatter), - withStack(1024*8, false), + WithCustomFormatter(c.panicFormatter), + WithStack(1024*8, false), ), wrappedResponseWriterFilter(), // wraps response for easy status access serverNameFilter(c.name, c.version), @@ -142,7 +142,11 @@ func NewHTTPTransport( cfg := newConfig(name) for _, ofn := range options { - ofn(cfg) + er := ofn(cfg) + + if er != nil { + return nil, er + } } return cfg.build()