Skip to content

Commit 4a35e76

Browse files
committed
fix: misc linter fixes
Signed-off-by: Liam Stanley <liam@liam.sh>
1 parent a075f0b commit 4a35e76

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

bind.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package chix
66

77
import (
88
"encoding/json"
9+
"errors"
910
"fmt"
1011
"net/http"
1112
"strings"
@@ -97,7 +98,8 @@ handle:
9798
if DefaultValidator != nil {
9899
err = DefaultValidator.Struct(v)
99100
if err != nil {
100-
if _, ok := err.(*validator.InvalidValidationError); ok {
101+
invalidValidationError := &validator.InvalidValidationError{}
102+
if errors.As(err, &invalidValidationError) {
101103
panic(fmt.Errorf("invalid validation error: %w", err))
102104
}
103105

logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ func UseStructuredLogger(logger log.Interface) func(next http.Handler) http.Hand
5050
bfields["rid"] = id
5151
}
5252

53-
if ray := r.Header.Get("CF-Ray"); ray != "" {
53+
if ray := r.Header.Get("Cf-Ray"); ray != "" {
5454
bfields["ray_id"] = ray
5555
}
5656

57-
if country := r.Header.Get("CF-IPCountry"); country != "" {
57+
if country := r.Header.Get("Cf-Ipcountry"); country != "" {
5858
bfields["country"] = country
5959
}
6060

realip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func UseRealIP(trusted []string, flags RealIPOptions) func(next http.Handler) ht
167167

168168
// Parse enabled headers by most specific (and common) to least.
169169
if flags&OptUseCFConnectingIP != 0 {
170-
if value := parseIP(r.Header.Get("CF-Connecting-IP")); value != nil {
170+
if value := parseIP(r.Header.Get("Cf-Connecting-Ip")); value != nil {
171171
r.RemoteAddr = value.String()
172172
goto nexthandler
173173
}

recoverer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package chix
66

77
import (
8+
"errors"
89
"fmt"
910
"net/http"
1011
"runtime/debug"
@@ -29,7 +30,7 @@ func UseRecoverer(next http.Handler) http.Handler {
2930
fn := func(w http.ResponseWriter, r *http.Request) {
3031
defer func() {
3132
if rvr := recover(); rvr != nil {
32-
if rvr == http.ErrAbortHandler {
33+
if e, ok := rvr.(error); ok && errors.Is(e, http.ErrAbortHandler) {
3334
panic(rvr)
3435
}
3536

recoverer_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package chix
66

77
import (
8+
"errors"
89
"net/http"
910
"net/http/httptest"
1011
"testing"
@@ -27,8 +28,13 @@ func TestUseRecoverer(t *testing.T) {
2728

2829
func TestUseRecovererAbort(t *testing.T) {
2930
defer func() {
30-
if rvr := recover(); rvr != http.ErrAbortHandler {
31+
if rvr := recover(); rvr != nil {
32+
if e, ok := rvr.(error); ok && errors.Is(e, http.ErrAbortHandler) {
33+
return
34+
}
3135
t.Fatalf("expected panic of type http.ErrAbortHandler, got %v", rvr)
36+
} else {
37+
t.Fatalf("expected panic of type http.ErrAbortHandler, got nil")
3238
}
3339
}()
3440

0 commit comments

Comments
 (0)