Skip to content

Commit

Permalink
fix: ci lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
uknth committed Oct 3, 2023
1 parent 45d5f8a commit 3f5e561
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 10 additions & 10 deletions transport/http/filter_panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -152,38 +152,38 @@ 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
r.stackOthers = false
}
}

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 }
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion transport/http/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
5 changes: 2 additions & 3 deletions transport/http/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package http
import (
"bytes"
"io"
"io/ioutil"
net_http "net/http"
)

Expand All @@ -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))
}
}

Expand All @@ -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)
}
}

Expand Down
12 changes: 8 additions & 4 deletions transport/http/transport_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 3f5e561

Please sign in to comment.