234 msformat337 mscheck 1115total 263errors 298warnings 554notes

Showing 1000 of 1115 detailed findings. The summary includes all 1115 findings.

context.go1

141:36add-constantstring literal "/" appears more than twice; define a constant

context.go:141:36

140 for strings.Contains(p, "/*/") {
141 p = strings.ReplaceAll(p, "/*/", "/")
142 }

mux_test.go1

1886:5boolean-literal-comparisonomit the boolean literal from the logical expression

mux_test.go:1886:5

1885 tctx.Reset()
1886 if r.Match(tctx, "GET", "/users/1") == false {
1887 t.Fatal("expecting to find match for route:", "GET", "/users/1")

middleware/client_ip.go1

217:6cognitive-complexityfunction has cognitive complexity 13; maximum is 7

middleware/client_ip.go:217:6

216// which value security logic sees by sending a duplicate header.
217func walkXFF(headers []string, visit func(entry string) bool) {
218 for hi := len(headers) - 1; hi >= 0; hi-- {

chain.go1

36:6confusing-namingname chain differs from Chain only by capitalization

chain.go:36:6

35// handler in the order they are passed.
36func chain(middlewares []func(http.Handler) http.Handler, endpoint http.Handler) http.Handler {
37 // Return ahead of time if there aren't any middlewares for the chain

middleware/content_charset.go1

37:38confusing-resultsadjacent unnamed results of the same type should be named

middleware/content_charset.go:37:38

36// Split a string in two parts, cleaning any whitespace.
37func split(str, sep string) (string, string) {
38 a, b, found := strings.Cut(str, sep)

mux_test.go1

1708:20context-cancel-in-loopcontext.WithCancel is created in a loop but its cancellation function is not called during the iteration

mux_test.go:1708:20

1707
1708 ctx, cancel := context.WithCancel(r.Context())
1709 r = r.WithContext(ctx)

context.go1

51:2context-stored-in-structdo not store context.Context in a struct; pass it explicitly to each operation

context.go:51:2

50 // 1 allocation.
51 parentCtx context.Context
52

middleware/get_head_test.go1

11:6cyclomatic-complexityfunction complexity is 13; maximum is 10

middleware/get_head_test.go:11:6

10
11func TestGetHead(t *testing.T) {
12 r := chi.NewRouter()

middleware/client_ip_example_test.go1

77:2discarded-error-resulterror result returned by fmt.Print is discarded

middleware/client_ip_example_test.go:77:2

76 r.ServeHTTP(w, req)
77 fmt.Print(w.Body.String())
78 // Output: 198.51.100.42

chi.go1

1:1doc-comment-perioddocumentation comment should end with punctuation

chi.go:1:1

1// Package chi is a small, idiomatic and composable router for building HTTP services.
2//

tree.go1

447:6early-returninvert the condition and return early to reduce nesting

tree.go:447:6

446 if p < 0 {
447 if xn.tail == '/' {
448 p = len(xsearch)

middleware/client_ip_test.go1

325:12error-stringserror string should not be capitalized or end with punctuation

middleware/client_ip_test.go:325:12

324 if got := GetClientIP(req.Context()); got != "" {
325 t.Errorf("GetClientIP on empty ctx: want %q, got %q", "", got)
326 }

middleware/middleware_test.go1

18:2excessive-blank-identifiersassignment discards three or more results; name meaningful results or simplify the return contract

middleware/middleware_test.go:18:2

17func init() {
18 _, filename, _, _ := runtime.Caller(0)
19 testdataDir = path.Join(path.Dir(filename), "/../testdata")

chain.go1

12:24exported-declaration-commentexported function or method should have a comment beginning with its name

chain.go:12:24

11// with `h http.Handler` as the final handler.
12func (mws Middlewares) Handler(h http.Handler) http.Handler {
13 return &ChainHandler{h, chain(mws, h), mws}

middleware/nocache.go1

45:19external-call-in-loopnet/http.Get is called synchronously inside a loop; batch or move the external operation outside the loop

middleware/nocache.go:45:19

44 for _, v := range etagHeaders {
45 if r.Header.Get(v) != "" {
46 r.Header.Del(v)

middleware/client_ip_test.go1

1:1file-length-limitfile has 736 lines; maximum is 500

middleware/client_ip_test.go:1:1

1package middleware
2

middleware/terminal.go1

55:22flag-parameterboolean parameter useColor controls function flow

middleware/terminal.go:55:22

54// colorWrite
55func cW(w io.Writer, useColor bool, color []byte, s string, args ...interface{}) {
56 if IsTTY && useColor {

chain.go1

1:1formatfile is not formatted

chain.go:1:1

1package chi
2
  • Fix (safe): run `strider fmt chain.go`

middleware/client_ip_test.go1

95:6function-lengthfunction has 8 statements and 79 lines; maximum is 50 statements or 75 lines

middleware/client_ip_test.go:95:6

94
95func TestClientIPFromXFF_TrustedPrefixes(t *testing.T) {
96 tt := []struct {

tree.go1

695:6function-result-limitfunction returns 6 values; maximum is 3

tree.go:695:6

694// node type, param key, regexp string, param tail byte, param starting index, param ending index
695func patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) {
696 ps := strings.Index(pattern, "{")

mux.go1

155:16get-function-return-valueGet-prefixed function should return a value

mux.go:155:16

154// execute the `handlerFn` http.HandlerFunc.
155func (mx *Mux) Get(pattern string, handlerFn http.HandlerFunc) {
156 mx.handle(mGET, pattern, handlerFn)

middleware/logger.go1

70:16import-shadowingidentifier bytes shadows an imported package

middleware/logger.go:70:16

69type LogEntry interface {
70 Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{})
71 Panic(v interface{}, stack []byte)

mux_test.go1

1395:18inefficient-sprintffmt.Sprintf is unnecessary for this conversion; use strconv.Itoa

mux_test.go:1395:18

1394 counter, _ := r.Context().Value(ctxKey{"counter"}).(int)
1395 w.Write([]byte(fmt.Sprintf("%v", counter)))
1396 }

middleware/strip_test.go1

295:47insecure-url-schemeURL uses insecure http scheme

middleware/strip_test.go:295:47

294 t.Run(tc.name, func(t *testing.T) {
295 req := httptest.NewRequest(http.MethodGet, "http://example.test"+tc.target, nil)
296 rr := httptest.NewRecorder()

chi.go1

66:13interface-method-limitinterface has 26 methods, exceeding the configured design limit of 10

chi.go:66:13

65// using only the standard net/http.
66type Router interface {
67 http.Handler

tree.go1

472:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:472:7

471 h := xn.endpoints[method]
472 if h != nil && h.handler != nil {
473 rctx.routeParams.Keys = append(rctx.routeParams.Keys, h.paramKeys...)

context.go1

141:3modifies-parameterassignment modifies parameter p

context.go:141:3

140 for strings.Contains(p, "/*/") {
141 p = strings.ReplaceAll(p, "/*/", "/")
142 }

middleware/route_headers.go1

52:3modifies-value-receiverassignment modifies value receiver hr

middleware/route_headers.go:52:3

51 if k == nil {
52 hr[header] = []HeaderRoute{}
53 }

middleware/client_ip_test.go1

13:10nested-structsmove nested anonymous struct types to named declarations

middleware/client_ip_test.go:13:10

12func TestClientIPFromHeader(t *testing.T) {
13 tt := []struct {
14 name string

mux_test.go1

721:6no-defer-in-loopdefer inside a loop runs at function exit, not iteration exit

mux_test.go:721:6

720 ts := httptest.NewServer(r)
721 defer ts.Close()
722

middleware/logger.go1

172:6no-initreplace init with explicit initialization

middleware/logger.go:172:6

171
172func init() {
173 color := true

tree.go1

788:2no-naked-returnreturn values must be explicit

tree.go:788:2

787 }
788 return
789}

context.go1

39:2no-package-varpackage variables introduce mutable global state

context.go:39:2

38 // RouteCtxKey is the context.Context key to store the request context.
39 RouteCtxKey = &contextKey{"RouteContext"}
40)

middleware/route_headers.go1

145:9optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

middleware/route_headers.go:145:9

144 }
145 return len(v) >= len(p.prefix+p.suffix) && strings.HasPrefix(v, p.prefix) && strings.HasSuffix(v, p.suffix)
146}

chain.go1

1:9package-commentspackage should have a documentation comment

chain.go:1:9

1package chi
2

middleware/compress_test.go1

115:3redefines-builtin-ididentifier recover shadows a predeclared identifier

middleware/compress_test.go:115:3

114 name string
115 recover string
116 types []string

tree.go1

81:8redundant-conversionconversion from methodTyp to the identical type is redundant

tree.go:81:8

80 }
81 mt := methodTyp(2 << n)
82 methodMap[method] = mt

middleware/compress_test.go1

197:2single-case-switchswitch with one case can be replaced by an if statement

middleware/compress_test.go:197:2

196 var reader io.ReadCloser
197 switch resp.Header.Get("Content-Encoding") {
198 case "gzip":

middleware/route_headers.go1

64:2slice-preallocationpreallocate patterns with capacity len(range source) before appending once per iteration

middleware/route_headers.go:64:2

63 }
64 patterns := []Pattern{}
65 for _, m := range match {

middleware/content_charset_test.go1

81:33standard-http-method-constantreplace the HTTP method literal with http.MethodGet

middleware/content_charset_test.go:81:33

80
81 var req, _ = http.NewRequest("GET", "/", nil)
82 req.Header.Set("Content-Type", tt.inputValue)

middleware/compress.go1

99:2task-commentTODO comment should be resolved or linked to an owned work item

middleware/compress.go:99:2

98 //
99 // TODO:
100 // lzma: Opera.

context_test.go1

24:6test-parallelismconsider calling t.Parallel() when this test begins

context_test.go:24:6

23// "/v1/resources/*/{resource_id}" (wrong)
24func TestRoutePattern(t *testing.T) {
25 routePatterns := []string{

chain.go1

24:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

chain.go:24:1

23// execution.
24type ChainHandler struct {
25 Endpoint http.Handler

middleware/compress.go1

223:26unchecked-type-assertionuse the checked two-result form of the type assertion

middleware/compress.go:223:26

222 if pool, ok := c.pooledEncoders[name]; ok {
223 encoder := pool.Get().(ioResetterWriter)
224 cleanup := func() {

middleware/middleware_test.go1

73:15unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

middleware/middleware_test.go:73:15

72
73 resp, err := client.Get("https://localhost:7072")
74 if err != nil {

tree.go1

138:44unexported-returnexported function returns an unexported type

tree.go:138:44

137
138func (s endpoints) Value(method methodTyp) *endpoint {
139 mh, ok := s[method]

middleware/logger.go1

140:52unused-parameterparameter header is unused

middleware/logger.go:140:52

139
140func (l *defaultLogEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
141 switch {

middleware/logger_test.go1

17:7unused-receiverreceiver cw is unused

middleware/logger_test.go:17:7

16
17func (cw testLoggerWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
18 return nil, nil, nil

middleware/compress.go1

167:16use-anyuse any instead of interface{}

middleware/compress.go:167:16

166 pool := &sync.Pool{
167 New: func() interface{} {
168 return fn(io.Discard, c.level)

context_test.go1

53:3add-constantstring literal "/v1/*" appears more than twice; define a constant

context_test.go:53:3

52 x.RoutePatterns = []string{
53 "/v1/*",
54 "/resources/*",

mux_test.go1

1891:5boolean-literal-comparisonomit the boolean literal from the logical expression

mux_test.go:1891:5

1890 tctx.Reset()
1891 if r.Match(tctx, "HEAD", "/articles/10") == true {
1892 t.Fatal("not expecting to find match for route:", "HEAD", "/articles/10")

middleware/compress.go1

65:6cognitive-complexityfunction has cognitive complexity 11; maximum is 7

middleware/compress.go:65:6

64// The types are the content types that are allowed to be compressed.
65func NewCompressor(level int, types ...string) *Compressor {
66 // If types are provided, set those as the allowed types. If none are

middleware/realip.go1

39:6confusing-namingname realIP differs from RealIP only by capitalization

middleware/realip.go:39:6

38
39func realIP(r *http.Request) string {
40 var ip string

tree.go1

695:55confusing-resultsadjacent unnamed results of the same type should be named

tree.go:695:55

694// node type, param key, regexp string, param tail byte, param starting index, param ending index
695func patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) {
696 ps := strings.Index(pattern, "{")

mux_test.go1

1349:3context-stored-in-structdo not store context.Context in a struct; pass it explicitly to each operation

mux_test.go:1349:3

1348 testcases := []struct {
1349 Ctx context.Context
1350 Method string

middleware/strip_test.go1

102:6cyclomatic-complexityfunction complexity is 24; maximum is 10

middleware/strip_test.go:102:6

101
102func TestRedirectSlashes(t *testing.T) {
103 r := chi.NewRouter()

middleware/compress.go1

346:3discarded-error-resulterror result returned by f.Flush is discarded

middleware/compress.go:346:3

345 if f, ok := cw.writer().(compressFlusher); ok {
346 f.Flush()
347

context.go1

109:1doc-comment-perioddocumentation comment should end with punctuation

context.go:109:1

108
109// RoutePattern builds the routing pattern string for the particular
110// request, at the particular point during routing. This means, the value

middleware/client_ip_test.go1

328:12error-stringserror string should not be capitalized or end with punctuation

middleware/client_ip_test.go:328:12

327 if got := GetClientIPAddr(req.Context()); got.IsValid() {
328 t.Errorf("GetClientIPAddr on empty ctx: want zero, got %v", got)
329 }

tree.go1

767:3excessive-blank-identifiersassignment discards three or more results; name meaningful results or simplify the return contract

tree.go:767:3

766 for {
767 ptyp, paramKey, _, _, _, e := patNextSegment(pat)
768 if ptyp == ntStatic {

chain.go1

18:24exported-declaration-commentexported function or method should have a comment beginning with its name

chain.go:18:24

17// with `h http.Handler` as the final handler.
18func (mws Middlewares) HandlerFunc(h http.HandlerFunc) http.Handler {
19 return &ChainHandler{h, chain(mws, h), mws}

middleware/route_headers.go1

87:31external-call-in-loopnet/http.Get is called synchronously inside a loop; batch or move the external operation outside the loop

middleware/route_headers.go:87:31

86 for header, matchers := range hr {
87 headerValue := r.Header.Get(header)
88 if headerValue == "" {

mux.go1

1:1file-length-limitfile has 533 lines; maximum is 500

mux.go:1:1

1package chi
2

chi.go1

1:1formatfile is not formatted

chi.go:1:1

1// Package chi is a small, idiomatic and composable router for building HTTP services.
2//
  • Fix (safe): run `strider fmt chi.go`

middleware/compress_test.go1

16:6function-lengthfunction has 28 statements and 95 lines; maximum is 50 statements or 75 lines

middleware/compress_test.go:16:6

15
16func TestCompressor(t *testing.T) {
17 r := chi.NewRouter()

middleware/logger.go1

140:41import-shadowingidentifier bytes shadows an imported package

middleware/logger.go:140:41

139
140func (l *defaultLogEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
141 switch {

tree.go1

477:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:477:7

476
477 for endpoints := range xn.endpoints {
478 if endpoints == mALL || endpoints == mSTUB {

middleware/compress.go1

150:2modifies-parameterassignment modifies parameter encoding

middleware/compress.go:150:2

149func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) {
150 encoding = strings.ToLower(encoding)
151 if encoding == "" {

middleware/route_headers.go1

54:2modifies-value-receiverassignment modifies value receiver hr

middleware/route_headers.go:54:2

53 }
54 hr[header] = append(hr[header], HeaderRoute{MatchOne: NewPattern(match), Middleware: middlewareHandler})
55 return hr

middleware/client_ip_test.go1

56:10nested-structsmove nested anonymous struct types to named declarations

middleware/client_ip_test.go:56:10

55func TestClientIPFromXFF_NoTrustedPrefixes(t *testing.T) {
56 tt := []struct {
57 name string

middleware/middleware_test.go1

17:6no-initreplace init with explicit initialization

middleware/middleware_test.go:17:6

16
17func init() {
18 _, filename, _, _ := runtime.Caller(0)

middleware/client_ip.go1

12:5no-package-varpackage variables introduce mutable global state

middleware/client_ip.go:12:5

11// clientIPCtxKey stores the client IP set by any of the ClientIPFrom* middlewares.
12var clientIPCtxKey = &contextKey{"clientIP"}
13

middleware/route_headers.go1

145:9optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

middleware/route_headers.go:145:9

144 }
145 return len(v) >= len(p.prefix+p.suffix) && strings.HasPrefix(v, p.prefix) && strings.HasSuffix(v, p.suffix)
146}

context.go1

1:9package-commentspackage should have a documentation comment

context.go:1:9

1package chi
2

middleware/path_rewrite.go1

9:23redefines-builtin-ididentifier new shadows a predeclared identifier

middleware/path_rewrite.go:9:23

8// PathRewrite is a simple middleware which allows you to rewrite the request URL path.
9func PathRewrite(old, new string) func(http.Handler) http.Handler {
10 return func(next http.Handler) http.Handler {

middleware/logger.go1

141:2single-case-switchswitch with one case can be replaced by an if statement

middleware/logger.go:141:2

140func (l *defaultLogEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
141 switch {
142 case status < 200:

path_value_test.go1

50:5slice-preallocationpreallocate pathValues with capacity len(range source) before appending once per iteration

path_value_test.go:50:5

49 r.Handle(tc.method+" "+tc.pattern, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
50 pathValues := []string{}
51 for _, pathKey := range tc.pathKeys {

middleware/realip_test.go1

12:28standard-http-method-constantreplace the HTTP method literal with http.MethodGet

middleware/realip_test.go:12:28

11func TestXRealIP(t *testing.T) {
12 req, _ := http.NewRequest("GET", "/", nil)
13 req.Header.Add("X-Real-IP", "100.100.100.100")

middleware/compress.go1

122:2task-commentTODO comment should be resolved or linked to an owned work item

middleware/compress.go:122:2

121
122 // TODO: Exception for old MSIE browsers that can't handle non-HTML?
123 // https://zoompf.com/blog/2012/02/lose-the-wait-http-compression

context_test.go1

97:6test-parallelismconsider calling t.Parallel() when this test begins

context_test.go:97:6

96// collapsed into a single slash.
97func TestReplaceWildcardsConsecutive(t *testing.T) {
98 if p := replaceWildcards("/foo/*/*/*/bar"); p != "/foo/bar" {

chi.go1

66:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

chi.go:66:1

65// using only the standard net/http.
66type Router interface {
67 http.Handler

middleware/wrap_writer.go1

149:36unchecked-type-assertionuse the checked two-result form of the type assertion

middleware/wrap_writer.go:149:36

148 f.wroteHeader = true
149 fl := f.basicWriter.ResponseWriter.(http.Flusher)
150 fl.Flush()

middleware/middleware_test.go1

89:15unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

middleware/middleware_test.go:89:15

88
89 resp, err := http.DefaultClient.Do(req)
90 if err != nil {

tree.go1

147:84unexported-returnexported function returns an unexported type

tree.go:147:84

146
147func (n *node) InsertRoute(method methodTyp, pattern string, handler http.Handler) *node {
148 var parent *node

middleware/logger.go1

140:95unused-parameterparameter extra is unused

middleware/logger.go:140:95

139
140func (l *defaultLogEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
141 switch {

middleware/recoverer.go1

132:7unused-receiverreceiver s is unused

middleware/recoverer.go:132:7

131
132func (s prettyStack) decorateFuncCallLine(line string, useColor bool, num int) (string, error) {
133 idx := strings.LastIndex(line, "(")

middleware/logger.go1

70:76use-anyuse any instead of interface{}

middleware/logger.go:70:76

69type LogEntry interface {
70 Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{})
71 Panic(v interface{}, stack []byte)

context_test.go1

54:3add-constantstring literal "/resources/*" appears more than twice; define a constant

context_test.go:54:3

53 "/v1/*",
54 "/resources/*",
55 // Even with many wildcards

mux_test.go1

1906:5boolean-literal-comparisonomit the boolean literal from the logical expression

mux_test.go:1906:5

1905 tctx.Reset()
1906 if r.Match(tctx, "GET", "/") != true {
1907 t.Fatal("expecting to find match for route:", "GET", "/")

middleware/compress.go1

213:22cognitive-complexityfunction has cognitive complexity 9; maximum is 7

middleware/compress.go:213:22

212// selectEncoder returns the encoder, the name of the encoder, and a closer function.
213func (c *Compressor) selectEncoder(h http.Header, w io.Writer) (io.Writer, string, func()) {
214 header := h.Get("Accept-Encoding")

middleware/recoverer.go1

61:6confusing-namingname printPrettyStack differs from PrintPrettyStack only by capitalization

middleware/recoverer.go:61:6

60// do not support them (e.g. on Windows) or when output is being captured.
61func printPrettyStack(rvr interface{}, useColor bool) {
62 debugStack := debug.Stack()

tree.go1

695:74confusing-resultsadjacent unnamed results of the same type should be named

tree.go:695:74

694// node type, param key, regexp string, param tail byte, param starting index, param ending index
695func patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) {
696 ps := strings.Index(pattern, "{")

middleware/throttle.go1

44:6cyclomatic-complexityfunction complexity is 12; maximum is 10

middleware/throttle.go:44:6

43// ThrottleWithOpts is a middleware that limits number of currently processed requests using passed ThrottleOpts.
44func ThrottleWithOpts(opts ThrottleOpts) func(http.Handler) http.Handler {
45 if opts.Limit < 1 {

middleware/compress_test.go1

36:3discarded-error-resulterror result returned by w.Write is discarded

middleware/compress_test.go:36:3

35 w.Header().Set("Content-Type", "text/html")
36 w.Write([]byte("textstring"))
37 })

context.go1

151:1doc-comment-perioddocumentation comment should end with punctuation

context.go:151:1

150
151// Add will append a URL parameter to the end of the route param
152func (s *RouteParams) Add(key, value string) {

middleware/client_ip_test.go1

347:12error-stringserror string should not be capitalized or end with punctuation

middleware/client_ip_test.go:347:12

346 if gotStr != "203.0.113.42" {
347 t.Errorf("GetClientIP: want 203.0.113.42, got %q", gotStr)
348 }

chain.go1

24:6exported-declaration-commentexported type should have a comment beginning with its name

chain.go:24:6

23// execution.
24type ChainHandler struct {
25 Endpoint http.Handler

middleware/throttle_test.go1

252:41external-call-in-loopnet/http.Get is called synchronously inside a loop; batch or move the external operation outside the loop

middleware/throttle_test.go:252:41

251 count429++
252 assertEqual(t, "3600", res.header.Get("Retry-After"))
253 continue

mux_test.go1

1:1file-length-limitfile has 2123 lines; maximum is 500

mux_test.go:1:1

1package chi
2

context.go1

1:1formatfile is not formatted

context.go:1:1

1package chi
2
  • Fix (safe): run `strider fmt context.go`

middleware/content_charset_test.go1

11:6function-lengthfunction has 16 statements and 82 lines; maximum is 50 statements or 75 lines

middleware/content_charset_test.go:11:6

10
11func TestContentCharset(t *testing.T) {
12 t.Parallel()

middleware/middleware_test.go1

82:61import-shadowingidentifier path shadows an imported package

middleware/middleware_test.go:82:61

81
82func testRequest(t *testing.T, ts *httptest.Server, method, path string, body io.Reader) (*http.Response, string) {
83 req, err := http.NewRequest(method, ts.URL+path, body)

tree.go1

478:8max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:478:8

477 for endpoints := range xn.endpoints {
478 if endpoints == mALL || endpoints == mSTUB {
479 continue

middleware/content_charset.go1

13:3modifies-parameterassignment modifies parameter charsets

middleware/content_charset.go:13:3

12 for i, c := range charsets {
13 charsets[i] = strings.ToLower(c)
14 }

middleware/route_headers.go1

62:3modifies-value-receiverassignment modifies value receiver hr

middleware/route_headers.go:62:3

61 if k == nil {
62 hr[header] = []HeaderRoute{}
63 }

middleware/client_ip_test.go1

96:10nested-structsmove nested anonymous struct types to named declarations

middleware/client_ip_test.go:96:10

95func TestClientIPFromXFF_TrustedPrefixes(t *testing.T) {
96 tt := []struct {
97 name string

middleware/request_id.go1

46:6no-initreplace init with explicit initialization

middleware/request_id.go:46:6

45
46func init() {
47 hostname, err := os.Hostname()

middleware/compress.go1

16:5no-package-varpackage variables introduce mutable global state

middleware/compress.go:16:5

15
16var defaultCompressibleContentTypes = []string{
17 "text/html",

middleware/wrap_writer.go1

28:6optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

middleware/wrap_writer.go:28:6

27 _, rf := w.(io.ReaderFrom)
28 if fl && hj && rf {
29 return &httpFancyWriter{bw}

middleware/basic_auth.go1

1:9package-commentspackage should have a documentation comment

middleware/basic_auth.go:1:9

1package middleware
2

middleware/throttle_test.go1

246:3single-case-switchswitch with one case can be replaced by an if statement

middleware/throttle_test.go:246:3

245 for res := range resultsCh {
246 switch res.status {
247 case http.StatusOK:

middleware/realip_test.go1

46:29standard-http-method-constantreplace the HTTP method literal with http.MethodGet

middleware/realip_test.go:46:29

45 for _, v := range xForwardedForIPs {
46 req, _ := http.NewRequest("GET", "/", nil)
47 req.Header.Add("X-Forwarded-For", v)

mux_test.go1

1313:1task-commentTODO comment should be resolved or linked to an owned work item

mux_test.go:1313:1

1312
1313// TODO: a Router wrapper test..
1314//

middleware/client_ip_test.go1

12:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:12:6

11
12func TestClientIPFromHeader(t *testing.T) {
13 tt := []struct {

context.go1

37:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

context.go:37:1

36
37var (
38 // RouteCtxKey is the context.Context key to store the request context.

middleware/wrap_writer.go1

161:36unchecked-type-assertionuse the checked two-result form of the type assertion

middleware/wrap_writer.go:161:36

160func (f *hijackWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
161 hj := f.basicWriter.ResponseWriter.(http.Hijacker)
162 return hj.Hijack()

middleware/middleware_test.go1

119:15unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

middleware/middleware_test.go:119:15

118
119 resp, err := httpClient.Do(req)
120 if err != nil {

tree.go1

382:73unexported-returnexported function returns an unexported type

tree.go:382:73

381
382func (n *node) FindRoute(rctx *Context, method methodTyp, path string) (*node, endpoints, http.Handler) {
383 // Reset the context routing pattern and params

middleware/logger.go1

168:48unused-parameterparameter stack is unused

middleware/logger.go:168:48

167
168func (l *defaultLogEntry) Panic(v interface{}, stack []byte) {
169 printPrettyStack(v, l.useColor)

middleware/recoverer.go1

172:7unused-receiverreceiver s is unused

middleware/recoverer.go:172:7

171
172func (s prettyStack) decorateSourceLine(line string, useColor bool, num int) (string, error) {
173 idx := strings.LastIndex(line, ".go:")

middleware/logger.go1

71:10use-anyuse any instead of interface{}

middleware/logger.go:71:10

70 Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{})
71 Panic(v interface{}, stack []byte)
72}

context_test.go1

57:3add-constantstring literal "/*" appears more than twice; define a constant

context_test.go:57:3

56 "/*",
57 "/*",
58 "/*",

mux_test.go1

1917:5boolean-literal-comparisonomit the boolean literal from the logical expression

mux_test.go:1917:5

1916 tctx.Reset()
1917 if r.Match(tctx, "GET", "/") != false {
1918 t.Fatal("not expecting to find match for route:", "GET", "/")

middleware/compress_test.go1

112:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

middleware/compress_test.go:112:6

111
112func TestCompressorWildcards(t *testing.T) {
113 tests := []struct {

mux.go1

422:16confusing-namingname handle differs from Handle only by capitalization

mux.go:422:16

421// and routing pattern.
422func (mx *Mux) handle(method methodTyp, pattern string, handler http.Handler) *node {
423 if len(pattern) == 0 || pattern[0] != '/' {

middleware/wrap_writer.go1

15:6cyclomatic-complexityfunction complexity is 11; maximum is 10

middleware/wrap_writer.go:15:6

14// hook into various parts of the response process.
15func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter {
16 _, fl := w.(http.Flusher)

middleware/compress_test.go1

41:3discarded-error-resulterror result returned by w.Write is discarded

middleware/compress_test.go:41:3

40 w.Header().Set("Content-Type", "text/html")
41 w.Write([]byte("textstring"))
42 })

context_test.go1

5:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:5:1

4
5// TestRoutePattern tests correct in-the-middle wildcard removals.
6// If user organizes a router like this:

middleware/client_ip_test.go1

350:12error-stringserror string should not be capitalized or end with punctuation

middleware/client_ip_test.go:350:12

349 if !gotAddr.IsValid() || gotAddr.String() != "203.0.113.42" {
350 t.Errorf("GetClientIPAddr: want 203.0.113.42, got %v", gotAddr)
351 }

chi.go1

66:6exported-declaration-commentexported type should have a comment beginning with its name

chi.go:66:6

65// using only the standard net/http.
66type Router interface {
67 http.Handler

tree.go1

1:1file-length-limitfile has 886 lines; maximum is 500

tree.go:1:1

1package chi
2

context_test.go1

1:1formatfile is not formatted

context_test.go:1:1

1package chi
2
  • Fix (safe): run `strider fmt context_test.go`

middleware/route_headers_test.go1

10:6function-lengthfunction has 94 statements and 176 lines; maximum is 50 statements or 75 lines

middleware/route_headers_test.go:10:6

9
10func TestRouteHeaders(t *testing.T) {
11 t.Run("empty router should call next handler exactly once", func(t *testing.T) {

middleware/middleware_test.go1

105:71import-shadowingidentifier path shadows an imported package

middleware/middleware_test.go:105:71

104
105func testRequestNoRedirect(t *testing.T, ts *httptest.Server, method, path string, body io.Reader) (*http.Response, string) {
106 req, err := http.NewRequest(method, ts.URL+path, body)

middleware/content_charset.go1

30:5modifies-parameterassignment modifies parameter ce

middleware/content_charset.go:30:5

29func contentEncoding(ce string, charsets ...string) bool {
30 _, ce = split(strings.ToLower(ce), ";")
31 _, ce = split(ce, "charset=")

middleware/route_headers.go1

68:2modifies-value-receiverassignment modifies value receiver hr

middleware/route_headers.go:68:2

67 }
68 hr[header] = append(hr[header], HeaderRoute{MatchAny: patterns, Middleware: middlewareHandler})
69 return hr

middleware/client_ip_test.go1

185:10nested-structsmove nested anonymous struct types to named declarations

middleware/client_ip_test.go:185:10

184func TestClientIPFromXFFTrustedProxies(t *testing.T) {
185 tt := []struct {
186 name string

middleware/terminal.go1

37:6no-initreplace init with explicit initialization

middleware/terminal.go:37:6

36
37func init() {
38 // This is sort of cheating: if stdout is a character device, we assume

middleware/logger.go1

15:2no-package-varpackage variables introduce mutable global state

middleware/logger.go:15:2

14 // LogEntryCtxKey is the context.Context key to store the request log entry.
15 LogEntryCtxKey = &contextKey{"LogEntry"}
16

middleware/wrap_writer.go1

83:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

middleware/wrap_writer.go:83:5

82func (b *basicWriter) WriteHeader(code int) {
83 if code >= 100 && code <= 199 && code != http.StatusSwitchingProtocols {
84 if !b.discard {

middleware/clean_path.go1

1:9package-commentspackage should have a documentation comment

middleware/clean_path.go:1:9

1package middleware
2

tree.go1

254:2single-case-switchswitch with one case can be replaced by an if statement

tree.go:254:2

253 // Add child depending on next up segment
254 switch segTyp {
255

middleware/realip_test.go1

69:28standard-http-method-constantreplace the HTTP method literal with http.MethodGet

middleware/realip_test.go:69:28

68func TestXForwardForXRealIPPrecedence(t *testing.T) {
69 req, _ := http.NewRequest("GET", "/", nil)
70 req.Header.Add("X-Forwarded-For", "0.0.0.0")

mux_test.go1

1324:1task-commentTODO comment should be resolved or linked to an owned work item

mux_test.go:1324:1

1323//
1324// // TODO: this should be supported...
1325// func TestWoot(t *testing.T) {

middleware/client_ip_test.go1

42:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:42:18

41 for _, tc := range tt {
42 t.Run(tc.name, func(t *testing.T) {
43 got := run(t, ClientIPFromHeader("X-Real-IP"), func(r *http.Request) {

middleware/client_ip.go1

16:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

middleware/client_ip.go:16:1

15// name, used by the XFF-based middlewares.
16const xForwardedForHeader = "X-Forwarded-For"
17

middleware/wrap_writer.go1

174:36unchecked-type-assertionuse the checked two-result form of the type assertion

middleware/wrap_writer.go:174:36

173 f.wroteHeader = true
174 fl := f.basicWriter.ResponseWriter.(http.Flusher)
175 fl.Flush()

middleware/throttle_test.go1

45:16unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

middleware/throttle_test.go:45:16

44
45 res, err := client.Get(server.URL)
46 assertNoError(t, err)

tree.go1

382:80unexported-returnexported function returns an unexported type

tree.go:382:80

381
382func (n *node) FindRoute(rctx *Context, method methodTyp, path string) (*node, endpoints, http.Handler) {
383 // Reset the context routing pattern and params

middleware/recoverer_test.go1

17:30unused-parameterparameter v is unused

middleware/recoverer_test.go:17:30

16
17func (testPrintLogger) Print(v ...interface{}) {}
18

mux.go1

493:7unused-receiverreceiver mx is unused

mux.go:493:7

492
493func (mx *Mux) nextRoutePath(rctx *Context) string {
494 routePath := "/"

middleware/logger.go1

88:13use-anyuse any instead of interface{}

middleware/logger.go:88:13

87type LoggerInterface interface {
88 Print(v ...interface{})
89}

context_test.go1

64:11add-constantstring literal "unexpected route pattern: " appears more than twice; define a constant

context_test.go:64:11

63 if p := x.RoutePattern(); p != "/v1/resources/{resource_id}/*" {
64 t.Fatal("unexpected route pattern: " + p)
65 }

tree_test.go1

427:5boolean-literal-comparisonomit the boolean literal from the logical expression

tree_test.go:427:5

426
427 if tr.findPattern("/pages") != false {
428 t.Errorf("find /pages failed")

middleware/get_head.go1

10:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

middleware/get_head.go:10:6

9// GetHead automatically route undefined HEAD requests to GET handlers.
10func GetHead(next http.Handler) http.Handler {
11 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

tree.go1

409:16confusing-namingname findRoute differs from FindRoute only by capitalization

tree.go:409:16

408// It's like searching through a multi-dimensional radix trie.
409func (n *node) findRoute(rctx *Context, method methodTyp, path string) *node {
410 nn := n

mux.go1

295:16cyclomatic-complexityfunction complexity is 17; maximum is 10

mux.go:295:16

294// if you define two Mount() routes on the exact same pattern the mount will panic.
295func (mx *Mux) Mount(pattern string, handler http.Handler) {
296 if handler == nil {

middleware/compress_test.go1

46:3discarded-error-resulterror result returned by w.Write is discarded

middleware/compress_test.go:46:3

45 w.Header().Set("Content-Type", "text/html")
46 w.Write([]byte("textstring"))
47 })

middleware/clean_path.go1

10:1doc-comment-perioddocumentation comment should end with punctuation

middleware/clean_path.go:10:1

9
10// CleanPath middleware will clean out double slash mistakes from a user's request path.
11// For example, if a user requests /users//1 or //users////1 will both be treated as: /users/1

middleware/client_ip_test.go1

353:12error-stringserror string should not be capitalized or end with punctuation

middleware/client_ip_test.go:353:12

352 if gotAddr.Is6() {
353 t.Errorf("GetClientIPAddr: want IPv4, got IPv6")
354 }

chi.go1

119:6exported-declaration-commentexported type should have a comment beginning with its name

chi.go:119:6

118// used by the `docgen` subpackage to generation documentation for Routers.
119type Routes interface {
120 // Routes returns the routing tree in an easily traversable structure.

tree_test.go1

1:1file-length-limitfile has 580 lines; maximum is 500

tree_test.go:1:1

1package chi
2

middleware/basic_auth.go1

1:1formatfile is not formatted

middleware/basic_auth.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/basic_auth.go`

middleware/strip_test.go1

102:6function-lengthfunction has 51 statements and 98 lines; maximum is 50 statements or 75 lines

middleware/strip_test.go:102:6

101
102func TestRedirectSlashes(t *testing.T) {
103 r := chi.NewRouter()

middleware/content_charset.go1

31:5modifies-parameterassignment modifies parameter ce

middleware/content_charset.go:31:5

30 _, ce = split(strings.ToLower(ce), ";")
31 _, ce = split(ce, "charset=")
32 ce, _ = split(ce, ";")

middleware/route_headers.go1

73:2modifies-value-receiverassignment modifies value receiver hr

middleware/route_headers.go:73:2

72func (hr HeaderRouter) RouteDefault(handler func(next http.Handler) http.Handler) HeaderRouter {
73 hr["*"] = []HeaderRoute{{Middleware: handler}}
74 return hr

middleware/client_ip_test.go1

247:10nested-structsmove nested anonymous struct types to named declarations

middleware/client_ip_test.go:247:10

246func TestClientIPFromRemoteAddr(t *testing.T) {
247 tt := []struct {
248 name string

middleware/logger.go1

20:2no-package-varpackage variables introduce mutable global state

middleware/logger.go:20:2

19 // logging configurations.
20 DefaultLogger func(next http.Handler) http.Handler
21)

middleware/wrap_writer.go1

210:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

middleware/wrap_writer.go:210:5

209func (f *httpFancyWriter) ReadFrom(r io.Reader) (int64, error) {
210 if f.basicWriter.tee != nil || f.basicWriter.discard {
211 // Route through basicWriter.Write so that the tee and discard semantics

middleware/client_ip.go1

1:9package-commentspackage should have a documentation comment

middleware/client_ip.go:1:9

1package middleware
2

tree.go1

427:3single-case-switchswitch with one case can be replaced by an if statement

tree.go:427:3

426
427 switch ntyp {
428 case ntStatic:

middleware/realip_test.go1

94:28standard-http-method-constantreplace the HTTP method literal with http.MethodGet

middleware/realip_test.go:94:28

93func TestInvalidIP(t *testing.T) {
94 req, _ := http.NewRequest("GET", "/", nil)
95 req.Header.Add("X-Real-IP", "100.100.100.1000")

tree_test.go1

173:2task-commentTODO comment should be resolved or linked to an owned work item

tree_test.go:173:2

172
173 // TODO: panic if we see {id}{x} because we're missing a delimiter, its not possible.
174 // also {:id}* is not possible.

middleware/client_ip_test.go1

55:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:55:6

54
55func TestClientIPFromXFF_NoTrustedPrefixes(t *testing.T) {
56 tt := []struct {

middleware/compress.go1

48:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

middleware/compress.go:48:1

47// Compressor represents a set of encoding configurations.
48type Compressor struct {
49 // The mapping of encoder names to encoder functions.

middleware/wrap_writer.go1

179:36unchecked-type-assertionuse the checked two-result form of the type assertion

middleware/wrap_writer.go:179:36

178func (f *flushHijackWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
179 hj := f.basicWriter.ResponseWriter.(http.Hijacker)
180 return hj.Hijack()

middleware/throttle_test.go1

116:16unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

middleware/throttle_test.go:116:16

115
116 res, err := client.Get(server.URL)
117 assertNoError(t, err)

mux_test.go1

2057:18unused-parameterparameter t is unused

mux_test.go:2057:18

2056
2057func testHandler(t *testing.T, h http.Handler, method, path string, body io.Reader) (*http.Response, string) {
2058 r, _ := http.NewRequest(method, path, body)

middleware/logger.go1

140:101use-anyuse any instead of interface{}

middleware/logger.go:140:101

139
140func (l *defaultLogEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
141 switch {

context_test.go1

73:3add-constantstring literal "/{resource_id}" appears more than twice; define a constant

context_test.go:73:3

72 "/with_asterisks*/*",
73 "/{resource_id}",
74 }

tree_test.go1

430:5boolean-literal-comparisonomit the boolean literal from the logical expression

tree_test.go:430:5

429 }
430 if tr.findPattern("/pages*") != false {
431 t.Errorf("find /pages* failed - should be nil")

middleware/get_head_test.go1

11:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

middleware/get_head_test.go:11:6

10
11func TestGetHead(t *testing.T) {
12 r := chi.NewRouter()

tree.go1

846:6confusing-namingname walk differs from Walk only by capitalization

tree.go:846:6

845
846func walk(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.Handler) http.Handler) error {
847 for _, route := range r.Routes() {

mux_test.go1

16:6cyclomatic-complexityfunction complexity is 20; maximum is 10

mux_test.go:16:6

15
16func TestMuxBasic(t *testing.T) {
17 var count uint64

middleware/compress_test.go1

214:2discarded-error-resulterror result returned by reader.Close is discarded

middleware/compress_test.go:214:2

213 }
214 reader.Close()
215

middleware/client_ip_example_test.go1

12:1doc-comment-perioddocumentation comment should end with punctuation

middleware/client_ip_example_test.go:12:1

11
12// Example_clientIP shows how to choose a ClientIPFrom* middleware. There is
13// no safe default — pick exactly ONE based on your network setup:

middleware/client_ip_test.go1

427:12error-stringserror string should not be capitalized or end with punctuation

middleware/client_ip_test.go:427:12

426 if capturedClientIP == "192.0.2.2" {
427 t.Errorf("VULNERABLE: returned attacker-supplied leftmost IP")
428 }

chi.go1

138:6exported-declaration-commentexported type should have a comment beginning with its name

chi.go:138:6

137// to compose middleware chains and http.Handler's.
138type Middlewares []func(http.Handler) http.Handler
139

middleware/clean_path.go1

1:1formatfile is not formatted

middleware/clean_path.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/clean_path.go`

middleware/throttle.go1

44:6function-lengthfunction has 44 statements and 88 lines; maximum is 50 statements or 75 lines

middleware/throttle.go:44:6

43// ThrottleWithOpts is a middleware that limits number of currently processed requests using passed ThrottleOpts.
44func ThrottleWithOpts(opts ThrottleOpts) func(http.Handler) http.Handler {
45 if opts.Limit < 1 {

middleware/content_charset.go1

32:2modifies-parameterassignment modifies parameter ce

middleware/content_charset.go:32:2

31 _, ce = split(ce, "charset=")
32 ce, _ = split(ce, ";")
33 return slices.Contains(charsets, ce)

tree.go1

142:3modifies-value-receiverassignment modifies value receiver s

tree.go:142:3

141 mh = &endpoint{}
142 s[method] = mh
143 }

middleware/client_ip_test.go1

504:10nested-structsmove nested anonymous struct types to named declarations

middleware/client_ip_test.go:504:10

503func TestClientIPFromHeader_MultiValueLastWins(t *testing.T) {
504 tt := []struct {
505 name string

middleware/middleware_test.go1

15:5no-package-varpackage variables introduce mutable global state

middleware/middleware_test.go:15:5

14
15var testdataDir string
16

mux.go1

308:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

mux.go:308:5

307 subr, ok := handler.(*Mux)
308 if ok && subr.notFoundHandler == nil && mx.notFoundHandler != nil {
309 subr.NotFound(mx.notFoundHandler)

middleware/compress.go1

1:9package-commentspackage should have a documentation comment

middleware/compress.go:1:9

1package middleware
2

tree.go1

601:3single-case-switchswitch with one case can be replaced by an if statement

tree.go:601:3

600
601 switch n.typ {
602 case ntStatic:

middleware/recoverer_test.go1

95:30standard-http-method-constantreplace the HTTP method literal with http.MethodGet

middleware/recoverer_test.go:95:30

94
95 req, err := http.NewRequest("GET", "/", nil)
96 if err != nil {

tree_test.go1

194:2task-commentTODO comment should be resolved or linked to an owned work item

tree_test.go:194:2

193
194 // TODO: make a separate test case for this one..
195 // tr.InsertRoute(mGET, "/articles/{id}/{id}", hStub1) // panic expected, we're duplicating param keys

middleware/client_ip_test.go1

82:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:82:18

81 for _, tc := range tt {
82 t.Run(tc.name, func(t *testing.T) {
83 got := run(t, ClientIPFromXFF(), func(r *http.Request) {

middleware/logger.go1

63:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

middleware/logger.go:63:1

62// See DefaultLogFormatter for an example implementation.
63type LogFormatter interface {
64 NewLogEntry(r *http.Request) LogEntry

middleware/wrap_writer.go1

196:36unchecked-type-assertionuse the checked two-result form of the type assertion

middleware/wrap_writer.go:196:36

195 f.wroteHeader = true
196 fl := f.basicWriter.ResponseWriter.(http.Flusher)
197 fl.Flush()

middleware/throttle_test.go1

131:16unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

middleware/throttle_test.go:131:16

130
131 res, err := client.Get(server.URL)
132 assertNoError(t, err)

middleware/logger.go1

168:35use-anyuse any instead of interface{}

middleware/logger.go:168:35

167
168func (l *defaultLogEntry) Panic(v interface{}, stack []byte) {
169 printPrettyStack(v, l.useColor)

middleware/client_ip_test.go1

21:79add-constantstring literal "2345:425:2ca1::567:5673:23b5" appears more than twice; define a constant

middleware/client_ip_test.go:21:79

20 {"ipv6_canonical", "2345:425:2ca1::567:5673:23b5", "2345:425:2ca1::567:5673:23b5"},
21 {"ipv6_uncompressed_normalized", "2345:0425:2CA1:0000:0000:0567:5673:23B5", "2345:425:2ca1::567:5673:23b5"},
22

tree_test.go1

433:5boolean-literal-comparisonomit the boolean literal from the logical expression

tree_test.go:433:5

432 }
433 if tr.findPattern("/pages/*") == false {
434 t.Errorf("find /pages/* failed")

middleware/recoverer.go1

76:22cognitive-complexityfunction has cognitive complexity 9; maximum is 7

middleware/recoverer.go:76:22

75
76func (s prettyStack) parse(debugStack []byte, rvr interface{}, useColor bool) ([]byte, error) {
77 var err error

mux_test.go1

497:6cyclomatic-complexityfunction complexity is 12; maximum is 10

mux_test.go:497:6

496
497func TestMuxComplicatedNotFound(t *testing.T) {
498 decorateRouter := func(r *Mux) {

middleware/content_charset_test.go1

81:17discarded-error-resulterror result returned by http.NewRequest is discarded

middleware/content_charset_test.go:81:17

80
81 var req, _ = http.NewRequest("GET", "/", nil)
82 req.Header.Set("Content-Type", tt.inputValue)

middleware/compress.go1

31:1doc-comment-perioddocumentation comment should end with punctuation

middleware/compress.go:31:1

30
31// Compress is a middleware that compresses response
32// body of a given content types to a data format based

middleware/client_ip_test.go1

537:14error-stringserror string should not be capitalized or end with punctuation

middleware/client_ip_test.go:537:14

536 if got != tc.out {
537 t.Errorf("VULNERABLE or wrong: want %q, got %q", tc.out, got)
538 }

context.go1

27:6exported-declaration-commentexported function or method should have a comment beginning with its name

context.go:27:6

26// http.Request Context.
27func RouteContext(ctx context.Context) *Context {
28 val, _ := ctx.Value(RouteCtxKey).(*Context)

middleware/client_ip.go1

1:1formatfile is not formatted

middleware/client_ip.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/client_ip.go`

mux_test.go1

16:6function-lengthfunction has 110 statements and 191 lines; maximum is 50 statements or 75 lines

mux_test.go:16:6

15
16func TestMuxBasic(t *testing.T) {
17 var count uint64

middleware/logger.go1

82:2modifies-parameterassignment modifies parameter r

middleware/logger.go:82:2

81func WithLogEntry(r *http.Request, entry LogEntry) *http.Request {
82 r = r.WithContext(context.WithValue(r.Context(), LogEntryCtxKey, entry))
83 return r

tree.go1

796:39modifies-value-receiverassignment modifies value receiver ns

tree.go:796:39

795func (ns nodes) Len() int { return len(ns) }
796func (ns nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }
797func (ns nodes) Less(i, j int) bool { return ns[i].label < ns[j].label }

middleware/client_ip_test.go1

558:10nested-structsmove nested anonymous struct types to named declarations

middleware/client_ip_test.go:558:10

557func TestXFF_V4MappedIPv6BypassesTrustedV4Prefix(t *testing.T) {
558 tt := []struct {
559 name string

middleware/nocache.go1

12:5no-package-varpackage variables introduce mutable global state

middleware/nocache.go:12:5

11// Unix epoch time
12var epoch = time.Unix(0, 0).UTC().Format(http.TimeFormat)
13

mux.go1

311:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

mux.go:311:5

310 }
311 if ok && subr.methodNotAllowedHandler == nil && mx.methodNotAllowedHandler != nil {
312 subr.MethodNotAllowed(mx.methodNotAllowedHandler)

middleware/content_charset.go1

1:9package-commentspackage should have a documentation comment

middleware/content_charset.go:1:9

1package middleware
2

middleware/request_id_test.go1

29:31standard-http-method-constantreplace the HTTP method literal with http.MethodGet

middleware/request_id_test.go:29:31

28 func() *http.Request {
29 req, _ := http.NewRequest("GET", "/", nil)
30 req.Header.Add("X-Request-Id", "req-123456")

middleware/client_ip_test.go1

95:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:95:6

94
95func TestClientIPFromXFF_TrustedPrefixes(t *testing.T) {
96 tt := []struct {

middleware/middleware.go1

17:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

middleware/middleware.go:17:1

16// for defining context keys was copied from Go 1.7's new use of context in net/http.
17type contextKey struct {
18 name string

middleware/wrap_writer.go1

201:36unchecked-type-assertionuse the checked two-result form of the type assertion

middleware/wrap_writer.go:201:36

200func (f *httpFancyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
201 hj := f.basicWriter.ResponseWriter.(http.Hijacker)
202 return hj.Hijack()

middleware/throttle_test.go1

169:16unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

middleware/throttle_test.go:169:16

168
169 res, err := client.Get(server.URL)
170 assertNoError(t, err)

middleware/middleware_test.go1

149:37use-anyuse any instead of interface{}

middleware/middleware_test.go:149:37

148
149func assertEqual(t *testing.T, a, b interface{}) {
150 t.Helper()

middleware/client_ip_test.go1

63:23add-constantstring literal "100.100.100.100" appears more than twice; define a constant

middleware/client_ip_test.go:63:23

62 {"empty", []string{""}, ""},
63 {"single", []string{"100.100.100.100"}, "100.100.100.100"},
64 {"comma_space", []string{"1.1.1.1, 2.2.2.2"}, "2.2.2.2"},

tree_test.go1

436:5boolean-literal-comparisonomit the boolean literal from the logical expression

tree_test.go:436:5

435 }
436 if tr.findPattern("/articles/{id}/*") == false {
437 t.Errorf("find /articles/{id}/* failed")

middleware/route_headers.go1

77:24cognitive-complexityfunction has cognitive complexity 11; maximum is 7

middleware/route_headers.go:77:24

76
77func (hr HeaderRouter) Handler(next http.Handler) http.Handler {
78 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

mux_test.go1

885:6cyclomatic-complexityfunction complexity is 16; maximum is 10

mux_test.go:885:6

884
885func TestMuxBig(t *testing.T) {
886 r := bigMux()

middleware/get_head_test.go1

16:3discarded-error-resulterror result returned by w.Write is discarded

middleware/get_head_test.go:16:3

15 w.Header().Set("X-Test", "yes")
16 w.Write([]byte("bye"))
17 })

middleware/compress.go1

134:1doc-comment-perioddocumentation comment should end with punctuation

middleware/compress.go:134:1

133
134// SetEncoder can be used to set the implementation of a compression algorithm.
135//

middleware/client_ip_test.go1

583:14error-stringserror string should not be capitalized or end with punctuation

middleware/client_ip_test.go:583:14

582 if got != tc.out {
583 t.Errorf("VULNERABLE: v4-mapped IPv6 escaped v4 trusted prefix — want %q, got %q", tc.out, got)
584 }

context.go1

45:6exported-declaration-commentexported type should have a comment beginning with its name

context.go:45:6

44// an optional routing path.
45type Context struct {
46 Routes Routes

middleware/client_ip_bench_test.go1

1:1formatfile is not formatted

middleware/client_ip_bench_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/client_ip_bench_test.go`

mux_test.go1

316:6function-lengthfunction has 46 statements and 77 lines; maximum is 50 statements or 75 lines

mux_test.go:316:6

315
316func TestMuxNestedNotFound(t *testing.T) {
317 r := NewRouter()

middleware/recoverer.go1

119:2modifies-parameterassignment modifies parameter line

middleware/recoverer.go:119:2

118func (s prettyStack) decorateLine(line string, useColor bool, num int) (string, error) {
119 line = strings.TrimSpace(line)
120 if strings.HasPrefix(line, "\t") || strings.Contains(line, ".go:") {

tree.go1

796:46modifies-value-receiverassignment modifies value receiver ns

tree.go:796:46

795func (ns nodes) Len() int { return len(ns) }
796func (ns nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }
797func (ns nodes) Less(i, j int) bool { return ns[i].label < ns[j].label }

middleware/client_ip_test.go1

616:10nested-structsmove nested anonymous struct types to named declarations

middleware/client_ip_test.go:616:10

615func TestClientIPFromRemoteAddr_V4MappedIsUnmapped(t *testing.T) {
616 tt := []struct {
617 name string

middleware/nocache.go1

15:5no-package-varpackage variables introduce mutable global state

middleware/nocache.go:15:5

14// Taken from https://github.com/mytrile/nocache
15var noCacheHeaders = map[string]string{
16 "Expires": epoch,

mux.go1

423:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

mux.go:423:5

422func (mx *Mux) handle(method methodTyp, pattern string, handler http.Handler) *node {
423 if len(pattern) == 0 || pattern[0] != '/' {
424 panic(fmt.Sprintf("chi: routing pattern must begin with '/' in '%s'", pattern))

middleware/content_encoding.go1

1:9package-commentspackage should have a documentation comment

middleware/content_encoding.go:1:9

1package middleware
2

middleware/request_id_test.go1

39:31standard-http-method-constantreplace the HTTP method literal with http.MethodGet

middleware/request_id_test.go:39:31

38 func() *http.Request {
39 req, _ := http.NewRequest("GET", "/", nil)
40 req.Header.Add("X-Trace-Id", "trace:abc123")

middleware/client_ip_test.go1

162:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:162:18

161 for _, tc := range tt {
162 t.Run(tc.name, func(t *testing.T) {
163 got := run(t, ClientIPFromXFF(tc.prefixes...), func(r *http.Request) {

middleware/recoverer.go1

52:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

middleware/recoverer.go:52:1

51// for ability to test the PrintPrettyStack function
52var recovererErrorWriter io.Writer = os.Stderr
53

middleware/wrap_writer.go1

206:37unchecked-type-assertionuse the checked two-result form of the type assertion

middleware/wrap_writer.go:206:37

205func (f *http2FancyWriter) Push(target string, opts *http.PushOptions) error {
206 return f.basicWriter.ResponseWriter.(http.Pusher).Push(target, opts)
207}

middleware/throttle_test.go1

189:16unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

middleware/throttle_test.go:189:16

188
189 res, err := client.Get(server.URL)
190 assertNoError(t, err)

middleware/recoverer.go1

54:27use-anyuse any instead of interface{}

middleware/recoverer.go:54:27

53
54func PrintPrettyStack(rvr interface{}) {
55 printPrettyStack(rvr, true)

middleware/client_ip_test.go1

66:47add-constantstring literal "2.2.2.2" appears more than twice; define a constant

middleware/client_ip_test.go:66:47

65 {"comma_no_space", []string{"1.1.1.1,2.2.2.2"}, "2.2.2.2"},
66 {"multi_header_merged", []string{"1.1.1.1", "2.2.2.2"}, "2.2.2.2"},
67 {"multi_header_with_commas", []string{"5.5.5.5, 6.6.6.6", "7.7.7.7, 4.4.4.4"}, "4.4.4.4"},

tree_test.go1

439:5boolean-literal-comparisonomit the boolean literal from the logical expression

tree_test.go:439:5

438 }
439 if tr.findPattern("/articles/{something}/*") == false {
440 t.Errorf("find /articles/{something}/* failed")

middleware/route_headers.go1

116:22cognitive-complexityfunction has cognitive complexity 8; maximum is 7

middleware/route_headers.go:116:22

115
116func (r HeaderRoute) IsMatch(value string) bool {
117 if len(r.MatchAny) > 0 {

mux_test.go1

1177:6cyclomatic-complexityfunction complexity is 12; maximum is 10

mux_test.go:1177:6

1176
1177func TestMuxSubroutes(t *testing.T) {
1178 hHubView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

middleware/get_head_test.go1

22:4discarded-error-resulterror result returned by w.Write is discarded

middleware/get_head_test.go:22:4

21 w.Header().Set("X-Article", id)
22 w.Write([]byte("article:" + id))
23 })

middleware/content_type.go1

8:1doc-comment-perioddocumentation comment should end with punctuation

middleware/content_type.go:8:1

7
8// SetHeader is a convenience handler to set a response header key/value
9func SetHeader(key, value string) func(http.Handler) http.Handler {

middleware/client_ip_test.go1

604:12error-stringserror string should not be capitalized or end with punctuation

middleware/client_ip_test.go:604:12

603 if got != "" {
604 t.Errorf("VULNERABLE: zoned IPv6 escaped v6 trusted prefix — want %q, got %q", "", got)
605 }

context.go1

100:19exported-declaration-commentexported function or method should have a comment beginning with its name

context.go:100:19

99// routing context.
100func (x *Context) URLParam(key string) string {
101 for k := len(x.URLParams.Keys) - 1; k >= 0; k-- {

middleware/client_ip_test.go1

1:1formatfile is not formatted

middleware/client_ip_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/client_ip_test.go`

mux_test.go1

497:6function-lengthfunction has 54 statements and 91 lines; maximum is 50 statements or 75 lines

mux_test.go:497:6

496
497func TestMuxComplicatedNotFound(t *testing.T) {
498 decorateRouter := func(r *Mux) {

middleware/route_headers.go1

49:2modifies-parameterassignment modifies parameter header

middleware/route_headers.go:49:2

48func (hr HeaderRouter) Route(header, match string, middlewareHandler func(next http.Handler) http.Handler) HeaderRouter {
49 header = strings.ToLower(header)
50 k := hr[header]

middleware/client_ip_test.go1

647:10nested-structsmove nested anonymous struct types to named declarations

middleware/client_ip_test.go:647:10

646func TestXFF_FailClosedOnUnparseable(t *testing.T) {
647 tt := []struct {
648 name string

middleware/nocache.go1

22:5no-package-varpackage variables introduce mutable global state

middleware/nocache.go:22:5

21
22var etagHeaders = []string{
23 "ETag",

mux_test.go1

701:24optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

mux_test.go:701:24

700 defer func() {
701 if r := recover(); r != nil && !tc.shouldPanic {
702 t.Errorf("Unexpected panic for pattern %s:\n%v", tc.pattern, r)

middleware/content_type.go1

1:9package-commentspackage should have a documentation comment

middleware/content_type.go:1:9

1package middleware
2

middleware/sunset_test.go1

15:29standard-http-method-constantreplace the HTTP method literal with http.MethodGet

middleware/sunset_test.go:15:29

14 t.Run("Sunset without link", func(t *testing.T) {
15 req, _ := http.NewRequest("GET", "/", nil)
16 w := httptest.NewRecorder()

middleware/client_ip_test.go1

175:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:175:6

174
175func TestClientIPFromXFF_PanicsOnBadPrefix(t *testing.T) {
176 defer func() {

middleware/recoverer_test.go1

15:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

middleware/recoverer_test.go:15:1

14
15type testPrintLogger struct{}
16

middleware/wrap_writer.go1

219:36unchecked-type-assertionuse the checked two-result form of the type assertion

middleware/wrap_writer.go:219:36

218 }
219 rf := f.basicWriter.ResponseWriter.(io.ReaderFrom)
220 f.basicWriter.maybeWriteHeader()

middleware/throttle_test.go1

235:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

middleware/throttle_test.go:235:14

234 defer wg.Done()
235 res, _ := client.Get(server.URL)
236 resultsCh <- result{status: res.StatusCode, header: res.Header}

middleware/recoverer.go1

61:27use-anyuse any instead of interface{}

middleware/recoverer.go:61:27

60// do not support them (e.g. on Windows) or when output is being captured.
61func printPrettyStack(rvr interface{}, useColor bool) {
62 debugStack := debug.Stack()

middleware/client_ip_test.go1

68:37add-constantstring literal "2001:db8::1" appears more than twice; define a constant

middleware/client_ip_test.go:68:37

67 {"multi_header_with_commas", []string{"5.5.5.5, 6.6.6.6", "7.7.7.7, 4.4.4.4"}, "4.4.4.4"},
68 {"ipv6", []string{"2001:db8::1"}, "2001:db8::1"},
69 {"mixed_v4_v6_rightmost_wins", []string{"203.0.113.1, 2001:db8::1"}, "2001:db8::1"},

tree_test.go1

442:5boolean-literal-comparisonomit the boolean literal from the logical expression

tree_test.go:442:5

441 }
442 if tr.findPattern("/articles/{slug}/{uid}/*") == false {
443 t.Errorf("find /articles/{slug}/{uid}/* failed")

middleware/strip_test.go1

102:6cognitive-complexityfunction has cognitive complexity 16; maximum is 7

middleware/strip_test.go:102:6

101
102func TestRedirectSlashes(t *testing.T) {
103 r := chi.NewRouter()

mux_test.go1

1807:6cyclomatic-complexityfunction complexity is 11; maximum is 10

mux_test.go:1807:6

1806
1807func TestQueryHTTPMethod(t *testing.T) {
1808 r := NewRouter()

middleware/get_head_test.go1

28:4discarded-error-resulterror result returned by w.Write is discarded

middleware/get_head_test.go:28:4

27 w.Header().Set("X-User", "-")
28 w.Write([]byte("user"))
29 })

middleware/logger.go1

23:1doc-comment-perioddocumentation comment should end with punctuation

middleware/logger.go:23:1

22
23// Logger is a middleware that logs the start and end of each request, along
24// with some useful data about what was requested, what the response status was,

middleware/compress_test.go1

158:15error-stringserror string should not be capitalized or end with punctuation

middleware/compress_test.go:158:15

157 if r := recover(); tt.recover != fmt.Sprintf("%v", r) {
158 t.Errorf("Unexpected value recovered: %v", r)
159 }

context.go1

123:19exported-declaration-commentexported function or method should have a comment beginning with its name

context.go:123:19

122// }
123func (x *Context) RoutePattern() string {
124 if x == nil {

middleware/compress.go1

1:1formatfile is not formatted

middleware/compress.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/compress.go`

mux_test.go1

642:6function-lengthfunction has 19 statements and 91 lines; maximum is 50 statements or 75 lines

mux_test.go:642:6

641
642func TestMuxHandlePatternValidation(t *testing.T) {
643 testCases := []struct {

middleware/route_headers.go1

59:2modifies-parameterassignment modifies parameter header

middleware/route_headers.go:59:2

58func (hr HeaderRouter) RouteAny(header string, match []string, middlewareHandler func(next http.Handler) http.Handler) HeaderRouter {
59 header = strings.ToLower(header)
60 k := hr[header]

middleware/compress.go1

54:30nested-structsmove nested anonymous struct types to named declarations

middleware/compress.go:54:30

53 // The set of content types allowed to be compressed.
54 allowedTypes map[string]struct{}
55 allowedWildcards map[string]struct{}

middleware/realip.go1

12:5no-package-varpackage variables introduce mutable global state

middleware/realip.go:12:5

11
12var trueClientIP = http.CanonicalHeaderKey("True-Client-IP")
13var xForwardedFor = http.CanonicalHeaderKey("X-Forwarded-For")

tree.go1

632:6optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:632:6

631 n.walk(func(eps endpoints, subroutes Routes) bool {
632 if eps[mSTUB] != nil && eps[mSTUB].handler != nil && subroutes == nil {
633 return false

middleware/get_head.go1

1:9package-commentspackage should have a documentation comment

middleware/get_head.go:1:9

1package middleware
2

middleware/sunset_test.go1

46:29standard-http-method-constantreplace the HTTP method literal with http.MethodGet

middleware/sunset_test.go:46:29

45 t.Run("Sunset with link", func(t *testing.T) {
46 req, _ := http.NewRequest("GET", "/", nil)
47 w := httptest.NewRecorder()

middleware/client_ip_test.go1

184:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:184:6

183
184func TestClientIPFromXFFTrustedProxies(t *testing.T) {
185 tt := []struct {

middleware/request_id.go1

21:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

middleware/request_id.go:21:1

20// RequestIDKey is the key that holds the unique request ID in a request context.
21const RequestIDKey ctxKeyRequestID = 0
22

middleware/wrap_writer.go1

241:36unchecked-type-assertionuse the checked two-result form of the type assertion

middleware/wrap_writer.go:241:36

240 f.wroteHeader = true
241 fl := f.basicWriter.ResponseWriter.(http.Flusher)
242 fl.Flush()

middleware/throttle_test.go1

288:17unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

middleware/throttle_test.go:288:17

287 go func() {
288 resp, err := client.Get(server.URL)
289 if err != nil {

middleware/recoverer.go1

76:51use-anyuse any instead of interface{}

middleware/recoverer.go:76:51

75
76func (s prettyStack) parse(debugStack []byte, rvr interface{}, useColor bool) ([]byte, error) {
77 var err error

middleware/client_ip_test.go1

79:82add-constantstring literal "127.0.0.1" appears more than twice; define a constant

middleware/client_ip_test.go:79:82

78 // See https://adam-p.ca/blog/2022/03/x-forwarded-for/ for more details.
79 {"weird_with_empties_then_valid_rightmost", []string{"oh, hi,,127.0.0.1,,,,"}, "127.0.0.1"},
80 }

middleware/strip_test.go1

276:6cognitive-complexityfunction has cognitive complexity 13; maximum is 7

middleware/strip_test.go:276:6

275
276func TestRedirectSlashes_PreventBackslashRelativeOpenRedirect(t *testing.T) {
277 h := RedirectSlashes(http.NotFoundHandler())

tree.go1

409:16cyclomatic-complexityfunction complexity is 37; maximum is 10

tree.go:409:16

408// It's like searching through a multi-dimensional radix trie.
409func (n *node) findRoute(rctx *Context, method methodTyp, path string) *node {
410 nn := n

middleware/get_head_test.go1

33:4discarded-error-resulterror result returned by w.Write is discarded

middleware/get_head_test.go:33:4

32 w.Header().Set("X-User", id)
33 w.Write([]byte("user:" + id))
34 })

middleware/nocache.go1

31:1doc-comment-perioddocumentation comment should end with punctuation

middleware/nocache.go:31:1

30
31// NoCache is a simple piece of middleware that sets a number of HTTP headers to prevent
32// a router (or subrouter) from being cached by an upstream proxy and/or client.

middleware/content_charset_test.go1

100:12error-stringserror string should not be capitalized or end with punctuation

middleware/content_charset_test.go:100:12

99 if s1 != "type1" || s2 != "type2" {
100 t.Errorf("Want type1, type2 got %s, %s", s1, s2)
101 }

middleware/clean_path.go1

12:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/clean_path.go:12:6

11// For example, if a user requests /users//1 or //users////1 will both be treated as: /users/1
12func CleanPath(next http.Handler) http.Handler {
13 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

middleware/compress_test.go1

1:1formatfile is not formatted

middleware/compress_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/compress_test.go`

mux_test.go1

956:6function-lengthfunction has 88 statements and 139 lines; maximum is 50 statements or 75 lines

mux_test.go:956:6

955
956func bigMux() Router {
957 var r *Mux

mux.go1

87:2modifies-parameterassignment modifies parameter r

mux.go:87:2

86 // NOTE: r.WithContext() causes 2 allocations and context.WithValue() causes 1 allocation
87 r = r.WithContext(context.WithValue(r.Context(), RouteCtxKey, rctx))
88

middleware/compress.go1

55:30nested-structsmove nested anonymous struct types to named declarations

middleware/compress.go:55:30

54 allowedTypes map[string]struct{}
55 allowedWildcards map[string]struct{}
56 // The list of encoders in order of decreasing precedence.

middleware/realip.go1

13:5no-package-varpackage variables introduce mutable global state

middleware/realip.go:13:5

12var trueClientIP = http.CanonicalHeaderKey("True-Client-IP")
13var xForwardedFor = http.CanonicalHeaderKey("X-Forwarded-For")
14var xRealIP = http.CanonicalHeaderKey("X-Real-IP")

tree.go1

704:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:704:5

703 // Sanity check
704 if ps >= 0 && ws >= 0 && ws < ps {
705 panic("chi: wildcard '*' must be the last pattern in a route, otherwise use a '{param}'")

middleware/heartbeat.go1

1:9package-commentspackage should have a documentation comment

middleware/heartbeat.go:1:9

1package middleware
2

mux_test.go1

1259:28standard-http-method-constantreplace the HTTP method literal with http.MethodGet

mux_test.go:1259:28

1258 router := r
1259 req, _ := http.NewRequest("GET", "/accounts/44/hi", nil)
1260

middleware/client_ip_test.go1

224:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:224:18

223 for _, tc := range tt {
224 t.Run(tc.name, func(t *testing.T) {
225 got := run(t, ClientIPFromXFFTrustedProxies(tc.n), func(r *http.Request) {

middleware/route_headers.go1

46:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

middleware/route_headers.go:46:1

45
46type HeaderRouter map[string][]HeaderRoute
47

mux.go1

81:22unchecked-type-assertionuse the checked two-result form of the type assertion

mux.go:81:22

80 // into the pool for reuse from another request.
81 rctx = mx.pool.Get().(*Context)
82 rctx.Reset()

mux_test.go1

166:15unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

mux_test.go:166:15

165 // HEAD /ping
166 resp, err := http.Head(ts.URL + "/ping")
167 if err != nil {

middleware/recoverer_test.go1

17:35use-anyuse any instead of interface{}

middleware/recoverer_test.go:17:35

16
17func (testPrintLogger) Print(v ...interface{}) {}
18

middleware/client_ip_test.go1

116:23add-constantstring literal "203.0.113.0/24" appears more than twice; define a constant

middleware/client_ip_test.go:116:23

115 name: "all_trusted_returns_empty",
116 prefixes: []string{"203.0.113.0/24"},
117 xff: []string{"203.0.113.10, 203.0.113.20"},

middleware/throttle.go1

44:6cognitive-complexityfunction has cognitive complexity 11; maximum is 7

middleware/throttle.go:44:6

43// ThrottleWithOpts is a middleware that limits number of currently processed requests using passed ThrottleOpts.
44func ThrottleWithOpts(opts ThrottleOpts) func(http.Handler) http.Handler {
45 if opts.Limit < 1 {

tree.go1

628:16cyclomatic-complexityfunction complexity is 13; maximum is 10

tree.go:628:16

627
628func (n *node) routes() []Route {
629 rts := []Route{}

middleware/heartbeat.go1

18:5discarded-error-resulterror result returned by w.Write is discarded

middleware/heartbeat.go:18:5

17 w.WriteHeader(http.StatusOK)
18 w.Write([]byte("."))
19 return

middleware/profiler.go1

13:1doc-comment-perioddocumentation comment should end with punctuation

middleware/profiler.go:13:1

12
13// Profiler is a convenient subrouter used for mounting net/http/pprof. ie.
14//

middleware/content_charset_test.go1

106:12error-stringserror string should not be capitalized or end with punctuation

middleware/content_charset_test.go:106:12

105 if s1 != "type1" {
106 t.Errorf("Want \"type1\" got \"%s\"", s1)
107 }

middleware/client_ip.go1

41:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/client_ip.go:41:6

40// stripped before storage.
41func ClientIPFromHeader(trustedHeader string) func(http.Handler) http.Handler {
42 header := http.CanonicalHeaderKey(trustedHeader)

middleware/content_charset.go1

1:1formatfile is not formatted

middleware/content_charset.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/content_charset.go`

mux_test.go1

1096:6function-lengthfunction has 41 statements and 80 lines; maximum is 50 statements or 75 lines

mux_test.go:1096:6

1095
1096func TestMuxSubroutesBasic(t *testing.T) {
1097 hIndex := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

mux.go1

333:3modifies-parameterassignment modifies parameter pattern

mux.go:333:3

332 mx.handle(mALL|mSTUB, pattern+"/", mountHandler)
333 pattern += "/"
334 }

middleware/compress.go1

68:34nested-structsmove nested anonymous struct types to named declarations

middleware/compress.go:68:34

67 // provided, use the default list.
68 allowedTypes := make(map[string]struct{})
69 allowedWildcards := make(map[string]struct{})

middleware/realip.go1

14:5no-package-varpackage variables introduce mutable global state

middleware/realip.go:14:5

13var xForwardedFor = http.CanonicalHeaderKey("X-Forwarded-For")
14var xRealIP = http.CanonicalHeaderKey("X-Real-IP")
15

middleware/logger.go1

1:9package-commentspackage should have a documentation comment

middleware/logger.go:1:9

1package middleware
2

mux_test.go1

1298:26standard-http-method-constantreplace the HTTP method literal with http.MethodGet

mux_test.go:1298:26

1297
1298 r, _ := http.NewRequest("GET", "/", nil)
1299 rctx := NewRouteContext()

middleware/client_ip_test.go1

237:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:237:6

236
237func TestClientIPFromXFFTrustedProxies_PanicsOnZero(t *testing.T) {
238 defer func() {

middleware/throttle.go1

134:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

middleware/throttle.go:134:1

133// token represents a request that is being processed.
134type token struct{}
135

mux.go1

449:40unchecked-type-assertionuse the checked two-result form of the type assertion

mux.go:449:40

448 // Grab the route context object
449 rctx := r.Context().Value(RouteCtxKey).(*Context)
450

mux_test.go1

2041:15unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

mux_test.go:2041:15

2040
2041 resp, err := http.DefaultClient.Do(req)
2042 if err != nil {

middleware/terminal.go1

55:69use-anyuse any instead of interface{}

middleware/terminal.go:55:69

54// colorWrite
55func cW(w io.Writer, useColor bool, color []byte, s string, args ...interface{}) {
56 if IsTTY && useColor {

middleware/client_ip_test.go1

169:14add-constantstring literal "want %q, got %q" appears more than twice; define a constant

middleware/client_ip_test.go:169:14

168 if got != tc.out {
169 t.Errorf("want %q, got %q", tc.out, got)
170 }

middleware/wrap_writer.go1

15:6cognitive-complexityfunction has cognitive complexity 10; maximum is 7

middleware/wrap_writer.go:15:6

14// hook into various parts of the response process.
15func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter {
16 _, fl := w.(http.Flusher)

tree.go1

695:6cyclomatic-complexityfunction complexity is 18; maximum is 10

tree.go:695:6

694// node type, param key, regexp string, param tail byte, param starting index, param ending index
695func patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) {
696 ps := strings.Index(pattern, "{")

middleware/middleware_test.go1

44:3discarded-error-resulterror result returned by w.Write is discarded

middleware/middleware_test.go:44:3

43
44 w.Write([]byte("OK"))
45 })

middleware/request_id.go1

23:1doc-comment-perioddocumentation comment should end with punctuation

middleware/request_id.go:23:1

22
23// RequestIDHeader is the name of the HTTP Header which contains the request id.
24// Exported so that it can be changed by developers

middleware/content_charset_test.go1

109:12error-stringserror string should not be capitalized or end with punctuation

middleware/content_charset_test.go:109:12

108 if s2 != "" {
109 t.Errorf("Want empty string got \"%s\"", s2)
110 }

middleware/client_ip.go1

85:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/client_ip.go:85:6

84// Panics at startup if any prefix is invalid.
85func ClientIPFromXFF(trustedIPPrefixes ...string) func(http.Handler) http.Handler {
86 prefixes := make([]netip.Prefix, len(trustedIPPrefixes))

middleware/content_charset_test.go1

1:1formatfile is not formatted

middleware/content_charset_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/content_charset_test.go`

mux_test.go1

1177:6function-lengthfunction has 73 statements and 114 lines; maximum is 50 statements or 75 lines

mux_test.go:1177:6

1176
1177func TestMuxSubroutes(t *testing.T) {
1178 hHubView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

mux.go1

389:3modifies-parameterassignment modifies parameter rctx

mux.go:389:3

388
389 rctx.RoutePath = mx.nextRoutePath(rctx)
390 subPattern := node.subroutes.Find(rctx, method, rctx.RoutePath)

middleware/compress.go1

69:38nested-structsmove nested anonymous struct types to named declarations

middleware/compress.go:69:38

68 allowedTypes := make(map[string]struct{})
69 allowedWildcards := make(map[string]struct{})
70 if len(types) > 0 {

middleware/recoverer.go1

52:5no-package-varpackage variables introduce mutable global state

middleware/recoverer.go:52:5

51// for ability to test the PrintPrettyStack function
52var recovererErrorWriter io.Writer = os.Stderr
53

middleware/maybe.go1

1:9package-commentspackage should have a documentation comment

middleware/maybe.go:1:9

1package middleware
2

mux_test.go1

1702:31standard-http-method-constantreplace the HTTP method literal with http.MethodGet

mux_test.go:1702:31

1701 w := httptest.NewRecorder()
1702 r, err := http.NewRequest("GET", "/ok", nil)
1703 if err != nil {

middleware/client_ip_test.go1

246:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:246:6

245
246func TestClientIPFromRemoteAddr(t *testing.T) {
247 tt := []struct {

middleware/wrap_writer.go1

48:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

middleware/wrap_writer.go:48:1

47// into various parts of the response process.
48type WrapResponseWriter interface {
49 http.ResponseWriter

mux_test.go1

53:36unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:53:36

52 ctx := r.Context()
53 user := ctx.Value(ctxKey{"user"}).(string)
54 w.WriteHeader(200)

middleware/value.go1

9:25use-anyuse any instead of interface{}

middleware/value.go:9:25

8// WithValue is a middleware that sets a given key/value in a context chain.
9func WithValue(key, val interface{}) func(next http.Handler) http.Handler {
10 return func(next http.Handler) http.Handler {

middleware/client_ip_test.go1

195:42add-constantstring literal "1.1.1.1, 2.2.2.2" appears more than twice; define a constant

middleware/client_ip_test.go:195:42

194 {"n3_third_from_right", 3, []string{"1.1.1.1, 2.2.2.2, 3.3.3.3, 4.4.4.4"}, "2.2.2.2"},
195 {"n2_exactly_matches_len", 2, []string{"1.1.1.1, 2.2.2.2"}, "1.1.1.1"},
196

middleware/wrap_writer.go1

82:23cognitive-complexityfunction has cognitive complexity 8; maximum is 7

middleware/wrap_writer.go:82:23

81
82func (b *basicWriter) WriteHeader(code int) {
83 if code >= 100 && code <= 199 && code != http.StatusSwitchingProtocols {

tree.go1

846:6cyclomatic-complexityfunction complexity is 11; maximum is 10

tree.go:846:6

845
846func walk(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.Handler) http.Handler) error {
847 for _, route := range r.Routes() {

middleware/realip_test.go1

12:12discarded-error-resulterror result returned by http.NewRequest is discarded

middleware/realip_test.go:12:12

11func TestXRealIP(t *testing.T) {
12 req, _ := http.NewRequest("GET", "/", nil)
13 req.Header.Add("X-Real-IP", "100.100.100.100")

middleware/route_headers.go1

8:1doc-comment-perioddocumentation comment should end with punctuation

middleware/route_headers.go:8:1

7
8// RouteHeaders is a neat little header-based router that allows you to direct
9// the flow of a request through a middleware stack based on a request header.

middleware/logger_test.go1

25:13error-stringserror string should not be capitalized or end with punctuation

middleware/logger_test.go:25:13

24 if !ok {
25 t.Errorf("http.Hijacker is unavailable on the writer. add the interface methods.")
26 }

middleware/client_ip.go1

138:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/client_ip.go:138:6

137// Panics at startup if numTrustedProxies < 1.
138func ClientIPFromXFFTrustedProxies(numTrustedProxies int) func(http.Handler) http.Handler {
139 if numTrustedProxies < 1 {

middleware/content_encoding_test.go1

1:1formatfile is not formatted

middleware/content_encoding_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/content_encoding_test.go`

mux_test.go1

1922:6function-lengthfunction has 52 statements and 83 lines; maximum is 50 statements or 75 lines

mux_test.go:1922:6

1921
1922func TestMuxFind(t *testing.T) {
1923 r := NewRouter()

mux.go1

481:3modifies-parameterassignment modifies parameter r

mux.go:481:3

480 }
481 r.Pattern = rctx.RoutePattern()
482

middleware/compress.go1

76:32nested-structsmove nested anonymous struct types to named declarations

middleware/compress.go:76:32

75 if before, ok := strings.CutSuffix(t, "/*"); ok {
76 allowedWildcards[before] = struct{}{}
77 } else {

middleware/request_id.go1

25:5no-package-varpackage variables introduce mutable global state

middleware/request_id.go:25:5

24// Exported so that it can be changed by developers
25var RequestIDHeader = "X-Request-Id"
26

middleware/middleware.go1

1:9package-commentspackage should have a documentation comment

middleware/middleware.go:1:9

1package middleware
2

mux_test.go1

2112:28standard-http-method-constantreplace the HTTP method literal with http.MethodGet

mux_test.go:2112:28

2111 w := httptest.NewRecorder()
2112 r, _ := http.NewRequest("GET", path, nil)
2113

middleware/client_ip_test.go1

259:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:259:18

258 for _, tc := range tt {
259 t.Run(tc.name, func(t *testing.T) {
260 got := run(t, ClientIPFromRemoteAddr, func(r *http.Request) {

mux_test.go2

2064:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

mux_test.go:2064:1

2063
2064type ctxKey struct {
2065 name string
336:43unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:336:43

335 }).NotFound(func(w http.ResponseWriter, r *http.Request) {
336 chkMw := r.Context().Value(ctxKey{"mw"}).(string)
337 chkWith := r.Context().Value(ctxKey{"with"}).(string)

mux.go1

54:24use-anyuse any instead of interface{}

mux.go:54:24

53 mux := &Mux{tree: &node{}, pool: &sync.Pool{}}
54 mux.pool.New = func() interface{} {
55 return NewRouteContext()

middleware/client_ip_test.go1

195:63add-constantstring literal "1.1.1.1" appears more than twice; define a constant

middleware/client_ip_test.go:195:63

194 {"n3_third_from_right", 3, []string{"1.1.1.1, 2.2.2.2, 3.3.3.3, 4.4.4.4"}, "2.2.2.2"},
195 {"n2_exactly_matches_len", 2, []string{"1.1.1.1, 2.2.2.2"}, "1.1.1.1"},
196

middleware/wrap_writer.go1

96:23cognitive-complexityfunction has cognitive complexity 8; maximum is 7

middleware/wrap_writer.go:96:23

95
96func (b *basicWriter) Write(buf []byte) (n int, err error) {
97 b.maybeWriteHeader()

middleware/realip_test.go1

22:3discarded-error-resulterror result returned by w.Write is discarded

middleware/realip_test.go:22:3

21 realIP = r.RemoteAddr
22 w.Write([]byte("Hello World"))
23 })

middleware/strip.go1

36:1doc-comment-perioddocumentation comment should end with punctuation

middleware/strip.go:36:1

35
36// RedirectSlashes is a middleware that will match request paths with a trailing
37// slash and redirect to the same path, less the trailing slash.

middleware/route_headers_test.go1

208:14error-stringserror string should not be capitalized or end with punctuation

middleware/route_headers_test.go:208:14

207 if got := p.Match(tt.value); got != tt.expected {
208 t.Errorf("Pattern(%q).Match(%q) = %v, want %v", tt.pattern, tt.value, got, tt.expected)
209 }

middleware/client_ip.go1

176:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/client_ip.go:176:6

175// IPv6 zones are preserved (link-local connections may legitimately have one).
176func ClientIPFromRemoteAddr(h http.Handler) http.Handler {
177 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

middleware/content_type.go1

1:1formatfile is not formatted

middleware/content_type.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/content_type.go`

tree.go2

147:16function-lengthfunction has 43 statements and 91 lines; maximum is 50 statements or 75 lines

tree.go:147:16

146
147func (n *node) InsertRoute(method methodTyp, pattern string, handler http.Handler) *node {
148 var parent *node
73:2modifies-parameterassignment modifies parameter method

tree.go:73:2

72 }
73 method = strings.ToUpper(method)
74 if _, ok := methodMap[method]; ok {

middleware/compress.go1

78:23nested-structsmove nested anonymous struct types to named declarations

middleware/compress.go:78:23

77 } else {
78 allowedTypes[t] = struct{}{}
79 }

middleware/request_id.go1

27:5no-package-varpackage variables introduce mutable global state

middleware/request_id.go:27:5

26
27var prefix string
28var reqid atomic.Uint64

middleware/nocache.go1

1:9package-commentspackage should have a documentation comment

middleware/nocache.go:1:9

1package middleware
2

middleware/client_ip_test.go1

276:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:276:6

275// first-write-wins semantics.
276func TestClientIPLastWriteWins(t *testing.T) {
277 t.Run("later_overrides_earlier", func(t *testing.T) {

tree.go1

19:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

tree.go:19:1

18
19const (
20 mSTUB methodTyp = 1 << iota

mux_test.go1

337:47unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:337:47

336 chkMw := r.Context().Value(ctxKey{"mw"}).(string)
337 chkWith := r.Context().Value(ctxKey{"with"}).(string)
338 w.WriteHeader(404)

middleware/client_ip_test.go1

220:48add-constantstring literal "::ffff:1.2.3.4" appears more than twice; define a constant

middleware/client_ip_test.go:220:48

219 // Normalization at the chosen position: v4-mapped IPv6 folds to v4, zone stripped.
220 {"v4_mapped_at_position_folded", 1, []string{"::ffff:1.2.3.4"}, "1.2.3.4"},
221 {"zone_stripped_at_position", 1, []string{"2001:db8::1%eth0"}, "2001:db8::1"},

mux.go1

295:16cognitive-complexityfunction has cognitive complexity 8; maximum is 7

mux.go:295:16

294// if you define two Mount() routes on the exact same pattern the mount will panic.
295func (mx *Mux) Mount(pattern string, handler http.Handler) {
296 if handler == nil {

middleware/realip_test.go1

46:13discarded-error-resulterror result returned by http.NewRequest is discarded

middleware/realip_test.go:46:13

45 for _, v := range xForwardedForIPs {
46 req, _ := http.NewRequest("GET", "/", nil)
47 req.Header.Add("X-Forwarded-For", v)

middleware/strip_test.go1

201:1doc-comment-perioddocumentation comment should end with punctuation

middleware/strip_test.go:201:1

200
201// This tests a http.Handler that is not chi.Router
202// In these cases, the routeContext is nil

mux_test.go1

702:15error-stringserror string should not be capitalized or end with punctuation

mux_test.go:702:15

701 if r := recover(); r != nil && !tc.shouldPanic {
702 t.Errorf("Unexpected panic for pattern %s:\n%v", tc.pattern, r)
703 }

middleware/client_ip.go1

192:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/client_ip.go:192:6

191// Convenient for logging, rate-limit keys, etc.
192func GetClientIP(ctx context.Context) string {
193 ip := GetClientIPAddr(ctx)

middleware/content_type_test.go1

1:1formatfile is not formatted

middleware/content_type_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/content_type_test.go`

tree.go2

243:16function-lengthfunction has 31 statements and 83 lines; maximum is 50 statements or 75 lines

tree.go:243:16

242// pattern segment is added to the url pattern tree as individual nodes, depending on type.
243func (n *node) addChild(child *node, prefix string) *node {
244 search := prefix
268:4modifies-parameterassignment modifies parameter child

tree.go:268:4

267 }
268 child.prefix = segRexpat
269 child.rex = rex

middleware/compress.go1

83:22nested-structsmove nested anonymous struct types to named declarations

middleware/compress.go:83:22

82 for _, t := range defaultCompressibleContentTypes {
83 allowedTypes[t] = struct{}{}
84 }

middleware/request_id.go1

28:5no-package-varpackage variables introduce mutable global state

middleware/request_id.go:28:5

27var prefix string
28var reqid atomic.Uint64
29

middleware/page_route.go1

1:9package-commentspackage should have a documentation comment

middleware/page_route.go:1:9

1package middleware
2

middleware/client_ip_test.go1

277:35test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:277:35

276func TestClientIPLastWriteWins(t *testing.T) {
277 t.Run("later_overrides_earlier", func(t *testing.T) {
278 got := runChain(t,

mux_test.go1

355:46unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:355:46

354 sr1.NotFound(func(w http.ResponseWriter, r *http.Request) {
355 chkMw2 := r.Context().Value(ctxKey{"mw2"}).(string)
356 w.WriteHeader(404)

middleware/client_ip_test.go1

220:67add-constantstring literal "1.2.3.4" appears more than twice; define a constant

middleware/client_ip_test.go:220:67

219 // Normalization at the chosen position: v4-mapped IPv6 folds to v4, zone stripped.
220 {"v4_mapped_at_position_folded", 1, []string{"::ffff:1.2.3.4"}, "1.2.3.4"},
221 {"zone_stripped_at_position", 1, []string{"2001:db8::1%eth0"}, "2001:db8::1"},

mux.go1

447:16cognitive-complexityfunction has cognitive complexity 11; maximum is 7

mux.go:447:16

446// the matching handler for a particular http method.
447func (mx *Mux) routeHTTP(w http.ResponseWriter, r *http.Request) {
448 // Grab the route context object

middleware/realip_test.go1

54:4discarded-error-resulterror result returned by w.Write is discarded

middleware/realip_test.go:54:4

53 realIP = r.RemoteAddr
54 w.Write([]byte("Hello World"))
55 })

middleware/sunset.go1

8:1doc-comment-perioddocumentation comment should end with punctuation

middleware/sunset.go:8:1

7
8// Sunset set Deprecation/Sunset header to response
9// This can be used to enable Sunset in a route or a route group

mux_test.go1

725:16error-stringserror string should not be capitalized or end with punctuation

mux_test.go:725:16

724 if body != tc.expectedBody || resp.StatusCode != tc.expectedStatus {
725 t.Errorf("Expected status %d and body %s; got status %d and body %s for pattern %s",
726 tc.expectedStatus, tc.expectedBody, resp.StatusCode, body, tc.pattern)

middleware/client_ip.go1

204:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/client_ip.go:204:6

203// prefix containment, Is4/Is6, etc. — without re-parsing the string.
204func GetClientIPAddr(ctx context.Context) netip.Addr {
205 ip, _ := ctx.Value(clientIPCtxKey).(netip.Addr)

middleware/get_head.go1

1:1formatfile is not formatted

middleware/get_head.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/get_head.go`

tree.go2

409:16function-lengthfunction has 72 statements and 144 lines; maximum is 50 statements or 75 lines

tree.go:409:16

408// It's like searching through a multi-dimensional radix trie.
409func (n *node) findRoute(rctx *Context, method methodTyp, path string) *node {
410 nn := n
269:4modifies-parameterassignment modifies parameter child

tree.go:269:4

268 child.prefix = segRexpat
269 child.rex = rex
270 }

middleware/compress.go1

269:30nested-structsmove nested anonymous struct types to named declarations

middleware/compress.go:269:30

268 w io.Writer
269 contentTypes map[string]struct{}
270 contentWildcards map[string]struct{}

middleware/terminal.go1

14:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:14:2

13 // Normal colors
14 nBlack = []byte{'\033', '[', '3', '0', 'm'}
15 nRed = []byte{'\033', '[', '3', '1', 'm'}

middleware/path_rewrite.go1

1:9package-commentspackage should have a documentation comment

middleware/path_rewrite.go:1:9

1package middleware
2

middleware/client_ip_test.go1

292:53test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:292:53

291
292 t.Run("earlier_persists_when_later_finds_nothing", func(t *testing.T) {
293 got := runChain(t,

mux_test.go1

614:45unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:614:45

613 r.With(mw1).With(mw2).Get("/inline", func(w http.ResponseWriter, r *http.Request) {
614 v1 := r.Context().Value(ctxKey{"inline1"}).(string)
615 v2 := r.Context().Value(ctxKey{"inline2"}).(string)

middleware/client_ip_test.go1

221:45add-constantstring literal "2001:db8::1%eth0" appears more than twice; define a constant

middleware/client_ip_test.go:221:45

220 {"v4_mapped_at_position_folded", 1, []string{"::ffff:1.2.3.4"}, "1.2.3.4"},
221 {"zone_stripped_at_position", 1, []string{"2001:db8::1%eth0"}, "2001:db8::1"},
222 }

mux_test.go1

16:6cognitive-complexityfunction has cognitive complexity 18; maximum is 7

mux_test.go:16:6

15
16func TestMuxBasic(t *testing.T) {
17 var count uint64

middleware/realip_test.go1

69:12discarded-error-resulterror result returned by http.NewRequest is discarded

middleware/realip_test.go:69:12

68func TestXForwardForXRealIPPrecedence(t *testing.T) {
69 req, _ := http.NewRequest("GET", "/", nil)
70 req.Header.Add("X-Forwarded-For", "0.0.0.0")

middleware/timeout.go1

9:1doc-comment-perioddocumentation comment should end with punctuation

middleware/timeout.go:9:1

8
9// Timeout is a middleware that cancels ctx after a given timeout and return
10// a 504 Gateway Timeout error to the client.

middleware/compress.go1

42:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/compress.go:42:6

41// Passing a compression level of 5 is sensible value
42func Compress(level int, types ...string) func(next http.Handler) http.Handler {
43 compressor := NewCompressor(level, types...)

middleware/get_head_test.go1

1:1formatfile is not formatted

middleware/get_head_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/get_head_test.go`

tree_test.go1

10:6function-lengthfunction has 70 statements and 143 lines; maximum is 50 statements or 75 lines

tree_test.go:10:6

9
10func TestTree(t *testing.T) {
11 hStub := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})

tree.go1

274:4modifies-parameterassignment modifies parameter child

tree.go:274:4

273 // Route starts with a param
274 child.typ = segTyp
275

middleware/compress.go1

270:30nested-structsmove nested anonymous struct types to named declarations

middleware/compress.go:270:30

269 contentTypes map[string]struct{}
270 contentWildcards map[string]struct{}
271 encoding string

middleware/terminal.go1

15:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:15:2

14 nBlack = []byte{'\033', '[', '3', '0', 'm'}
15 nRed = []byte{'\033', '[', '3', '1', 'm'}
16 nGreen = []byte{'\033', '[', '3', '2', 'm'}

middleware/profiler.go1

3:9package-commentspackage should have a documentation comment

middleware/profiler.go:3:9

2
3package middleware
4

middleware/client_ip_test.go1

306:55test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:306:55

305
306 t.Run("earlier_persists_when_later_xff_all_trusted", func(t *testing.T) {
307 got := runChain(t,

mux_test.go1

615:45unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:615:45

614 v1 := r.Context().Value(ctxKey{"inline1"}).(string)
615 v2 := r.Context().Value(ctxKey{"inline2"}).(string)
616 w.Write([]byte(fmt.Sprintf("inline %s %s", v1, v2)))

middleware/client_ip_test.go1

227:19add-constantstring literal "X-Forwarded-For" appears more than twice; define a constant

middleware/client_ip_test.go:227:19

226 for _, v := range tc.xff {
227 r.Header.Add("X-Forwarded-For", v)
228 }

mux_test.go1

431:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

mux_test.go:431:6

430
431func TestMuxNestedMethodNotAllowed(t *testing.T) {
432 r := NewRouter()

middleware/realip_test.go1

80:3discarded-error-resulterror result returned by w.Write is discarded

middleware/realip_test.go:80:3

79 realIP = r.RemoteAddr
80 w.Write([]byte("Hello World"))
81 })

middleware/url_format.go1

17:1doc-comment-perioddocumentation comment should end with punctuation

middleware/url_format.go:17:1

16
17// URLFormat is a middleware that parses the url extension from a request path and stores it
18// on the context as a string under the key `middleware.URLFormatCtxKey`. The middleware will

middleware/compress.go1

65:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/compress.go:65:6

64// The types are the content types that are allowed to be compressed.
65func NewCompressor(level int, types ...string) *Compressor {
66 // If types are provided, set those as the allowed types. If none are

middleware/logger.go1

1:1formatfile is not formatted

middleware/logger.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/logger.go`

tree_test.go1

154:6function-lengthfunction has 53 statements and 115 lines; maximum is 50 statements or 75 lines

tree_test.go:154:6

153
154func TestTreeMoar(t *testing.T) {
155 hStub := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})

tree.go1

284:4modifies-parameterassignment modifies parameter child

tree.go:284:4

283 }
284 child.tail = segTail // for params, we set the tail
285

middleware/compress_test.go1

52:13nested-structsmove nested anonymous struct types to named declarations

middleware/compress_test.go:52:13

51
52 tests := []struct {
53 name string

middleware/terminal.go1

16:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:16:2

15 nRed = []byte{'\033', '[', '3', '1', 'm'}
16 nGreen = []byte{'\033', '[', '3', '2', 'm'}
17 nYellow = []byte{'\033', '[', '3', '3', 'm'}

middleware/realip.go1

1:9package-commentspackage should have a documentation comment

middleware/realip.go:1:9

1package middleware
2

middleware/client_ip_test.go1

322:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:322:6

321
322func TestGetClientIPAddr_Unset(t *testing.T) {
323 req := httptest.NewRequest("GET", "/", nil)

mux_test.go1

804:63unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:804:63

803 ctx := r.Context()
804 ctxmwHandlerCount := ctx.Value(ctxKey{"count.ctxmwHandler"}).(uint64)
805 w.Write([]byte(fmt.Sprintf("inits:%d reqs:%d ctxValue:%d", ctxmwInit, handlerCount, ctxmwHandlerCount)))

middleware/client_ip_test.go1

254:30add-constantstring literal "192.0.2.1" appears more than twice; define a constant

middleware/client_ip_test.go:254:30

253 {"ipv6_with_port", "[2001:db8::1]:1234", "2001:db8::1"},
254 {"bare_ipv4", "192.0.2.1", "192.0.2.1"},
255 {"empty", "", ""},

mux_test.go1

497:6cognitive-complexityfunction has cognitive complexity 11; maximum is 7

mux_test.go:497:6

496
497func TestMuxComplicatedNotFound(t *testing.T) {
498 decorateRouter := func(r *Mux) {

middleware/realip_test.go1

94:12discarded-error-resulterror result returned by http.NewRequest is discarded

middleware/realip_test.go:94:12

93func TestInvalidIP(t *testing.T) {
94 req, _ := http.NewRequest("GET", "/", nil)
95 req.Header.Add("X-Real-IP", "100.100.100.1000")

tree.go1

67:1doc-comment-perioddocumentation comment should end with punctuation

tree.go:67:1

66
67// RegisterMethod adds support for custom HTTP method handlers, available
68// via Router#Method and Router#MethodFunc

middleware/compress.go1

149:22exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/compress.go:149:22

148// })
149func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) {
150 encoding = strings.ToLower(encoding)

middleware/logger_test.go1

1:1formatfile is not formatted

middleware/logger_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/logger_test.go`

tree.go1

305:4modifies-parameterassignment modifies parameter child

tree.go:305:4

304 // starts with a static segment
305 child.typ = ntStatic
306 child.prefix = search[:segStartIdx]

middleware/compress_test.go1

113:13nested-structsmove nested anonymous struct types to named declarations

middleware/compress_test.go:113:13

112func TestCompressorWildcards(t *testing.T) {
113 tests := []struct {
114 name string

middleware/terminal.go1

17:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:17:2

16 nGreen = []byte{'\033', '[', '3', '2', 'm'}
17 nYellow = []byte{'\033', '[', '3', '3', 'm'}
18 nBlue = []byte{'\033', '[', '3', '4', 'm'}

middleware/recoverer.go1

1:9package-commentspackage should have a documentation comment

middleware/recoverer.go:1:9

1package middleware
2

middleware/client_ip_test.go1

332:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:332:6

331
332func TestGetClientIPAddr_RoundTrip(t *testing.T) {
333 var gotStr string

mux_test.go1

1025:9unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:1025:9

1024 r.Route("/hubs", func(r Router) {
1025 _ = r.(*Mux) // sr1
1026 r.Route("/{hubID}", func(r Router) {

middleware/client_ip_test.go1

255:4add-constantstring literal "empty" appears more than twice; define a constant

middleware/client_ip_test.go:255:4

254 {"bare_ipv4", "192.0.2.1", "192.0.2.1"},
255 {"empty", "", ""},
256 {"garbage", "not-an-ip", ""},

mux_test.go1

642:6cognitive-complexityfunction has cognitive complexity 12; maximum is 7

mux_test.go:642:6

641
642func TestMuxHandlePatternValidation(t *testing.T) {
643 testCases := []struct {

middleware/realip_test.go1

104:3discarded-error-resulterror result returned by w.Write is discarded

middleware/realip_test.go:104:3

103 realIP = r.RemoteAddr
104 w.Write([]byte("Hello World"))
105 })

tree.go1

793:1doc-comment-perioddocumentation comment should end with punctuation

tree.go:793:1

792
793// Sort the list of nodes by label
794func (ns nodes) Sort() { sort.Sort(ns); ns.tailSort() }

middleware/compress.go1

189:22exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/compress.go:189:22

188// current Compressor.
189func (c *Compressor) Handler(next http.Handler) http.Handler {
190 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

middleware/middleware.go1

1:1formatfile is not formatted

middleware/middleware.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/middleware.go`

tree.go1

306:4modifies-parameterassignment modifies parameter child

tree.go:306:4

305 child.typ = ntStatic
306 child.prefix = search[:segStartIdx]
307 child.rex = nil

middleware/content_charset_test.go1

14:16nested-structsmove nested anonymous struct types to named declarations

middleware/content_charset_test.go:14:16

13
14 var tests = []struct {
15 name string

middleware/terminal.go1

18:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:18:2

17 nYellow = []byte{'\033', '[', '3', '3', 'm'}
18 nBlue = []byte{'\033', '[', '3', '4', 'm'}
19 nMagenta = []byte{'\033', '[', '3', '5', 'm'}

middleware/request_id.go1

1:9package-commentspackage should have a documentation comment

middleware/request_id.go:1:9

1package middleware
2

middleware/client_ip_test.go1

362:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:362:6

361// shapes the application might choose.
362func TestAdvisory_GHSA_3fxj_6jh8_hvhx(t *testing.T) {
363 // (a) Server directly on the internet: use ClientIPFromRemoteAddr.

mux_test.go1

1027:10unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:1027:10

1026 r.Route("/{hubID}", func(r Router) {
1027 _ = r.(*Mux) // sr2
1028 r.Get("/", func(w http.ResponseWriter, r *http.Request) {

middleware/client_ip_test.go1

296:24add-constantstring literal "CF-Connecting-IP" appears more than twice; define a constant

middleware/client_ip_test.go:296:24

295 ClientIPFromXFF(),
296 ClientIPFromHeader("CF-Connecting-IP"), // missing → no-op.
297 },

mux_test.go1

885:6cognitive-complexityfunction has cognitive complexity 15; maximum is 7

mux_test.go:885:6

884
885func TestMuxBig(t *testing.T) {
886 r := bigMux()

middleware/recoverer.go1

66:3discarded-error-resulterror result returned by recovererErrorWriter.Write is discarded

middleware/recoverer.go:66:3

65 if err == nil {
66 recovererErrorWriter.Write(out)
67 } else {

tree.go1

830:1doc-comment-perioddocumentation comment should end with punctuation

tree.go:830:1

829
830// Route describes the details of a routing handler.
831// Handlers map key is an HTTP method

middleware/compress.go1

255:6exported-declaration-commentexported type should have a comment beginning with its name

middleware/compress.go:255:6

254// In case of failure, the function should return nil.
255type EncoderFunc func(w io.Writer, level int) io.Writer
256

middleware/middleware_test.go1

1:1formatfile is not formatted

middleware/middleware_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/middleware_test.go`

tree.go1

307:4modifies-parameterassignment modifies parameter child

tree.go:307:4

306 child.prefix = search[:segStartIdx]
307 child.rex = nil
308

middleware/content_encoding.go1

11:38nested-structsmove nested anonymous struct types to named declarations

middleware/content_encoding.go:11:38

10func AllowContentEncoding(contentEncoding ...string) func(next http.Handler) http.Handler {
11 allowedEncodings := make(map[string]struct{}, len(contentEncoding))
12 for _, encoding := range contentEncoding {

middleware/terminal.go1

19:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:19:2

18 nBlue = []byte{'\033', '[', '3', '4', 'm'}
19 nMagenta = []byte{'\033', '[', '3', '5', 'm'}
20 nCyan = []byte{'\033', '[', '3', '6', 'm'}

middleware/request_size.go1

1:9package-commentspackage should have a documentation comment

middleware/request_size.go:1:9

1package middleware
2

middleware/client_ip_test.go1

365:43test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:365:43

364 // XFF is never consulted; the spoofed admin IP is ignored.
365 t.Run("direct_internet_uses_remoteaddr", func(t *testing.T) {
366 var clientIP string

mux_test.go1

1049:11unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:1049:11

1048 sr3.Route("/{webhookID}", func(r Router) {
1049 _ = r.(*Mux) // sr4
1050 r.Get("/", func(w http.ResponseWriter, r *http.Request) {

middleware/client_ip_test.go1

301:13add-constantstring literal "8.8.8.8" appears more than twice; define a constant

middleware/client_ip_test.go:301:13

300 })
301 if got != "8.8.8.8" {
302 t.Errorf("want 8.8.8.8, got %q", got)

mux_test.go1

1177:6cognitive-complexityfunction has cognitive complexity 11; maximum is 7

mux_test.go:1177:6

1176
1177func TestMuxSubroutes(t *testing.T) {
1178 hHubView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

middleware/recoverer.go1

69:3discarded-error-resulterror result returned by os.Stderr.Write is discarded

middleware/recoverer.go:69:3

68 // print stdlib output as a fallback
69 os.Stderr.Write(debugStack)
70 }

middleware/compress.go1

292:35exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/compress.go:292:35

291
292func (cw *compressResponseWriter) WriteHeader(code int) {
293 if cw.wroteHeader {

middleware/page_route.go1

1:1formatfile is not formatted

middleware/page_route.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/page_route.go`

tree.go1

384:2modifies-parameterassignment modifies parameter rctx

tree.go:384:2

383 // Reset the context routing pattern and params
384 rctx.routePattern = ""
385 rctx.routeParams.Keys = rctx.routeParams.Keys[:0]

middleware/content_encoding.go1

13:68nested-structsmove nested anonymous struct types to named declarations

middleware/content_encoding.go:13:68

12 for _, encoding := range contentEncoding {
13 allowedEncodings[strings.TrimSpace(strings.ToLower(encoding))] = struct{}{}
14 }

middleware/terminal.go1

20:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:20:2

19 nMagenta = []byte{'\033', '[', '3', '5', 'm'}
20 nCyan = []byte{'\033', '[', '3', '6', 'm'}
21 nWhite = []byte{'\033', '[', '3', '7', 'm'}

middleware/route_headers.go1

1:9package-commentspackage should have a documentation comment

middleware/route_headers.go:1:9

1package middleware
2

middleware/client_ip_test.go1

390:33test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:390:33

389 // entry is the genuine attacker IP, never the prepended spoof.
390 t.Run("behind_proxy_uses_xff", func(t *testing.T) {
391 got := run(t, ClientIPFromXFF("10.0.0.0/8"), func(r *http.Request) {

mux_test.go1

1065:11unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:1065:11

1064 r.Route("/posts", func(r Router) {
1065 _ = r.(*Mux) // sr5
1066 r.Get("/", func(w http.ResponseWriter, r *http.Request) {

middleware/client_ip_test.go1

336:27add-constantstring literal "X-Real-IP" appears more than twice; define a constant

middleware/client_ip_test.go:336:27

335 r := chi.NewRouter()
336 r.Use(ClientIPFromHeader("X-Real-IP"))
337 r.Get("/", func(w http.ResponseWriter, r *http.Request) {

mux_test.go1

1336:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

mux_test.go:1336:6

1335
1336func TestServeHTTPExistingContext(t *testing.T) {
1337 r := NewRouter()

middleware/request_id.go1

54:3discarded-error-resulterror result returned by rand.Read is discarded

middleware/request_id.go:54:3

53 for len(b64) < 10 {
54 rand.Read(buf[:])
55 b64 = base64.StdEncoding.EncodeToString(buf[:])

middleware/compress.go1

339:35exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/compress.go:339:35

338
339func (cw *compressResponseWriter) Flush() {
340 if f, ok := cw.writer().(http.Flusher); ok {

middleware/realip.go1

1:1formatfile is not formatted

middleware/realip.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/realip.go`

tree.go1

385:2modifies-parameterassignment modifies parameter rctx

tree.go:385:2

384 rctx.routePattern = ""
385 rctx.routeParams.Keys = rctx.routeParams.Keys[:0]
386 rctx.routeParams.Values = rctx.routeParams.Values[:0]

middleware/content_encoding_test.go1

22:13nested-structsmove nested anonymous struct types to named declarations

middleware/content_encoding_test.go:22:13

21
22 tests := []struct {
23 name string

middleware/terminal.go1

21:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:21:2

20 nCyan = []byte{'\033', '[', '3', '6', 'm'}
21 nWhite = []byte{'\033', '[', '3', '7', 'm'}
22 // Bright colors

middleware/strip.go1

1:9package-commentspackage should have a documentation comment

middleware/strip.go:1:9

1package middleware
2

middleware/client_ip_test.go1

406:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:406:6

405// never mutate r.RemoteAddr.
406func TestAdvisory_GHSA_9g5q_2w5x_hmxf(t *testing.T) {
407 originalRemoteAddr := "203.0.113.99:1234"

mux_test.go1

1077:9unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:1077:9

1076 r.Route("/folders/", func(r Router) {
1077 _ = r.(*Mux) // sr6
1078 r.Get("/", func(w http.ResponseWriter, r *http.Request) {

middleware/client_ip_test.go1

342:36add-constantstring literal "/" appears more than twice; define a constant

middleware/client_ip_test.go:342:36

341
342 req := httptest.NewRequest("GET", "/", nil)
343 req.Header.Set("X-Real-IP", "203.0.113.42")

path_value_test.go1

10:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

path_value_test.go:10:6

9
10func TestPathValue(t *testing.T) {
11 testCases := []struct {

middleware/request_id_test.go1

29:15discarded-error-resulterror result returned by http.NewRequest is discarded

middleware/request_id_test.go:29:15

28 func() *http.Request {
29 req, _ := http.NewRequest("GET", "/", nil)
30 req.Header.Add("X-Request-Id", "req-123456")

middleware/compress.go1

355:35exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/compress.go:355:35

354
355func (cw *compressResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
356 if hj, ok := cw.writer().(http.Hijacker); ok {

middleware/recoverer.go1

1:1formatfile is not formatted

middleware/recoverer.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/recoverer.go`

tree.go1

386:2modifies-parameterassignment modifies parameter rctx

tree.go:386:2

385 rctx.routeParams.Keys = rctx.routeParams.Keys[:0]
386 rctx.routeParams.Values = rctx.routeParams.Values[:0]
387

middleware/content_type.go1

21:41nested-structsmove nested anonymous struct types to named declarations

middleware/content_type.go:21:41

20func AllowContentType(contentTypes ...string) func(http.Handler) http.Handler {
21 allowedContentTypes := make(map[string]struct{}, len(contentTypes))
22 for _, ctype := range contentTypes {

middleware/terminal.go1

23:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:23:2

22 // Bright colors
23 bBlack = []byte{'\033', '[', '3', '0', ';', '1', 'm'}
24 bRed = []byte{'\033', '[', '3', '1', ';', '1', 'm'}

middleware/sunset.go1

1:9package-commentspackage should have a documentation comment

middleware/sunset.go:1:9

1package middleware
2

middleware/client_ip_test.go1

440:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:440:6

439// rightmost-untrusted for XFF.
440func TestAdvisory_GHSA_rjr7_jggh_pgcp(t *testing.T) {
441 // Attacker sends "X-Forwarded-For: 127.0.0.1" to spoof loopback. In a real

mux_test.go1

1211:8unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:1211:8

1210 r.Route("/accounts/{accountID}", func(r Router) {
1211 _ = r.(*Mux) // sr2
1212 // r.Get("/", hAccountView1)

middleware/client_ip_test.go1

349:47add-constantstring literal "203.0.113.42" appears more than twice; define a constant

middleware/client_ip_test.go:349:47

348 }
349 if !gotAddr.IsValid() || gotAddr.String() != "203.0.113.42" {
350 t.Errorf("GetClientIPAddr: want 203.0.113.42, got %v", gotAddr)

tree.go1

147:16cognitive-complexityfunction has cognitive complexity 17; maximum is 7

tree.go:147:16

146
147func (n *node) InsertRoute(method methodTyp, pattern string, handler http.Handler) *node {
148 var parent *node

middleware/request_id_test.go1

39:15discarded-error-resulterror result returned by http.NewRequest is discarded

middleware/request_id_test.go:39:15

38 func() *http.Request {
39 req, _ := http.NewRequest("GET", "/", nil)
40 req.Header.Add("X-Trace-Id", "trace:abc123")

middleware/compress.go1

362:35exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/compress.go:362:35

361
362func (cw *compressResponseWriter) Push(target string, opts *http.PushOptions) error {
363 if ps, ok := cw.writer().(http.Pusher); ok {

middleware/recoverer_test.go1

1:1formatfile is not formatted

middleware/recoverer_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/recoverer_test.go`

tree.go1

395:2modifies-parameterassignment modifies parameter rctx

tree.go:395:2

394 // Record the routing params in the request lifecycle
395 rctx.URLParams.Keys = append(rctx.URLParams.Keys, rctx.routeParams.Keys...)
396 rctx.URLParams.Values = append(rctx.URLParams.Values, rctx.routeParams.Values...)

middleware/content_type.go1

23:68nested-structsmove nested anonymous struct types to named declarations

middleware/content_type.go:23:68

22 for _, ctype := range contentTypes {
23 allowedContentTypes[strings.TrimSpace(strings.ToLower(ctype))] = struct{}{}
24 }

middleware/terminal.go1

24:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:24:2

23 bBlack = []byte{'\033', '[', '3', '0', ';', '1', 'm'}
24 bRed = []byte{'\033', '[', '3', '1', ';', '1', 'm'}
25 bGreen = []byte{'\033', '[', '3', '2', ';', '1', 'm'}

middleware/supress_notfound.go1

1:9package-commentspackage should have a documentation comment

middleware/supress_notfound.go:1:9

1package middleware
2

middleware/client_ip_test.go1

444:39test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:444:39

443 // rightmost-untrusted entry is never the loopback spoof.
444 t.Run("xff_loopback_spoof_rejected", func(t *testing.T) {
445 got := run(t, ClientIPFromXFF("10.0.0.0/8"), func(r *http.Request) {

mux_test.go1

2009:47unchecked-type-assertionuse the checked two-result form of the type assertion

mux_test.go:2009:47

2008 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
2009 baseYes := r.Context().Value(ctxKey{"base"}).(string)
2010 if _, ok := r.Context().Value(http.ServerContextKey).(*http.Server); !ok {

middleware/client_ip_test.go1

373:30add-constantstring literal "GET" appears more than twice; define a constant

middleware/client_ip_test.go:373:30

372
373 req := httptest.NewRequest("GET", "/admin", nil)
374 req.RemoteAddr = "99.99.99.99:1234"

tree.go1

243:16cognitive-complexityfunction has cognitive complexity 20; maximum is 7

tree.go:243:16

242// pattern segment is added to the url pattern tree as individual nodes, depending on type.
243func (n *node) addChild(child *node, prefix string) *node {
244 search := prefix

middleware/request_id_test.go1

63:4discarded-error-resulterror result returned by w.Write is discarded

middleware/request_id_test.go:63:4

62
63 w.Write([]byte(response))
64 })

middleware/compress.go1

369:35exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/compress.go:369:35

368
369func (cw *compressResponseWriter) Close() error {
370 if c, ok := cw.writer().(io.WriteCloser); ok {

middleware/request_id.go1

1:1formatfile is not formatted

middleware/request_id.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/request_id.go`

tree.go1

396:2modifies-parameterassignment modifies parameter rctx

tree.go:396:2

395 rctx.URLParams.Keys = append(rctx.URLParams.Keys, rctx.routeParams.Keys...)
396 rctx.URLParams.Values = append(rctx.URLParams.Values, rctx.routeParams.Values...)
397

middleware/content_type_test.go1

15:16nested-structsmove nested anonymous struct types to named declarations

middleware/content_type_test.go:15:16

14
15 var tests = []struct {
16 name string

middleware/terminal.go2

25:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:25:2

24 bRed = []byte{'\033', '[', '3', '1', ';', '1', 'm'}
25 bGreen = []byte{'\033', '[', '3', '2', ';', '1', 'm'}
26 bYellow = []byte{'\033', '[', '3', '3', ';', '1', 'm'}
1:9package-commentspackage should have a documentation comment

middleware/terminal.go:1:9

1package middleware
2

middleware/client_ip_test.go2

458:40test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:458:40

457 // into. Attacker-supplied True-Client-IP / X-Forwarded-For are ignored.
458 t.Run("only_opted_in_header_is_read", func(t *testing.T) {
459 got := run(t, ClientIPFromHeader("X-Real-IP"), func(r *http.Request) {
445:33add-constantstring literal "10.0.0.0/8" appears more than twice; define a constant

middleware/client_ip_test.go:445:33

444 t.Run("xff_loopback_spoof_rejected", func(t *testing.T) {
445 got := run(t, ClientIPFromXFF("10.0.0.0/8"), func(r *http.Request) {
446 r.Header.Set("X-Forwarded-For", "127.0.0.1, 99.99.99.99")

tree.go1

409:16cognitive-complexityfunction has cognitive complexity 113; maximum is 7

tree.go:409:16

408// It's like searching through a multi-dimensional radix trie.
409func (n *node) findRoute(rctx *Context, method methodTyp, path string) *node {
410 nn := n

middleware/strip_test.go1

22:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:22:3

21 w.WriteHeader(404)
22 w.Write([]byte("nothing here"))
23 })

middleware/content_charset.go1

11:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/content_charset.go:11:6

10// An empty charset will allow requests with no Content-Type header or no specified charset.
11func ContentCharset(charsets ...string) func(next http.Handler) http.Handler {
12 for i, c := range charsets {

middleware/request_id_test.go1

1:1formatfile is not formatted

middleware/request_id_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/request_id_test.go`

tree.go1

400:3modifies-parameterassignment modifies parameter rctx

tree.go:400:3

399 if rn.endpoints[method].pattern != "" {
400 rctx.routePattern = rn.endpoints[method].pattern
401 rctx.RoutePatterns = append(rctx.RoutePatterns, rctx.routePattern)

middleware/request_id_test.go1

21:22nested-structsmove nested anonymous struct types to named declarations

middleware/request_id_test.go:21:22

20func TestRequestID(t *testing.T) {
21 tests := map[string]struct {
22 requestIDHeader string

middleware/terminal.go1

26:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:26:2

25 bGreen = []byte{'\033', '[', '3', '2', ';', '1', 'm'}
26 bYellow = []byte{'\033', '[', '3', '3', ';', '1', 'm'}
27 bBlue = []byte{'\033', '[', '3', '4', ';', '1', 'm'}

middleware/throttle.go1

1:9package-commentspackage should have a documentation comment

middleware/throttle.go:1:9

1package middleware
2

middleware/client_ip_test.go2

476:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:476:6

475// See https://adam-p.ca/blog/2022/03/x-forwarded-for/ "Multiple headers".
476func TestXFF_MultipleHeadersMerged(t *testing.T) {
477 // Attacker sends two XFF headers; the trusted proxy appends to the second
451:13add-constantstring literal "99.99.99.99" appears more than twice; define a constant

middleware/client_ip_test.go:451:13

450 }
451 if got != "99.99.99.99" {
452 t.Errorf("want 99.99.99.99 (rightmost-untrusted), got %q", got)

tree.go1

554:16cognitive-complexityfunction has cognitive complexity 12; maximum is 7

tree.go:554:16

553
554func (n *node) findEdge(ntyp nodeTyp, label byte) *node {
555 nds := n.children[ntyp]

middleware/strip_test.go1

26:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:26:3

25 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
26 w.Write([]byte("root"))
27 })

middleware/content_encoding.go1

10:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/content_encoding.go:10:6

9// with a 415 Unsupported Media Type status.
10func AllowContentEncoding(contentEncoding ...string) func(next http.Handler) http.Handler {
11 allowedEncodings := make(map[string]struct{}, len(contentEncoding))

middleware/request_size.go1

1:1formatfile is not formatted

middleware/request_size.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/request_size.go`

tree.go1

401:3modifies-parameterassignment modifies parameter rctx

tree.go:401:3

400 rctx.routePattern = rn.endpoints[method].pattern
401 rctx.RoutePatterns = append(rctx.RoutePatterns, rctx.routePattern)
402 }

middleware/route_headers_test.go1

188:13nested-structsmove nested anonymous struct types to named declarations

middleware/route_headers_test.go:188:13

187func TestPattern(t *testing.T) {
188 tests := []struct {
189 pattern string

middleware/terminal.go1

27:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:27:2

26 bYellow = []byte{'\033', '[', '3', '3', ';', '1', 'm'}
27 bBlue = []byte{'\033', '[', '3', '4', ';', '1', 'm'}
28 bMagenta = []byte{'\033', '[', '3', '5', ';', '1', 'm'}

middleware/timeout.go1

1:9package-commentspackage should have a documentation comment

middleware/timeout.go:1:9

1package middleware
2

middleware/client_ip_test.go2

503:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:503:6

502// came from hops further from us and are less trustworthy by definition.
503func TestClientIPFromHeader_MultiValueLastWins(t *testing.T) {
504 tt := []struct {
600:32add-constantstring literal "2606:4700::/32" appears more than twice; define a constant

middleware/client_ip_test.go:600:32

599func TestXFF_IPv6ZoneIDBypassesTrustedV6Prefix(t *testing.T) {
600 got := run(t, ClientIPFromXFF("2606:4700::/32"), func(r *http.Request) {
601 r.Header.Set("X-Forwarded-For", "2606:4700::1%attacker, 2606:4700::5")

tree.go1

586:16cognitive-complexityfunction has cognitive complexity 15; maximum is 7

tree.go:586:16

585
586func (n *node) findPattern(pattern string) bool {
587 nn := n

middleware/strip_test.go1

32:4discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:32:4

31 accountID := chi.URLParam(r, "accountID")
32 w.Write([]byte(accountID))
33 })

middleware/content_type.go1

20:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/content_type.go:20:6

19// with a 415 Unsupported Media Type status.
20func AllowContentType(contentTypes ...string) func(http.Handler) http.Handler {
21 allowedContentTypes := make(map[string]struct{}, len(contentTypes))

middleware/route_headers.go1

1:1formatfile is not formatted

middleware/route_headers.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/route_headers.go`

tree.go1

466:5modifies-parameterassignment modifies parameter rctx

tree.go:466:5

465 prevlen := len(rctx.routeParams.Values)
466 rctx.routeParams.Values = append(rctx.routeParams.Values, xsearch[:p])
467 xsearch = xsearch[p:]

middleware/strip_test.go1

279:13nested-structsmove nested anonymous struct types to named declarations

middleware/strip_test.go:279:13

278
279 tests := []struct {
280 name string

middleware/terminal.go1

28:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:28:2

27 bBlue = []byte{'\033', '[', '3', '4', ';', '1', 'm'}
28 bMagenta = []byte{'\033', '[', '3', '5', ';', '1', 'm'}
29 bCyan = []byte{'\033', '[', '3', '6', ';', '1', 'm'}

middleware/url_format.go1

1:9package-commentspackage should have a documentation comment

middleware/url_format.go:1:9

1package middleware
2

middleware/client_ip_test.go2

530:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:530:18

529 for _, tc := range tt {
530 t.Run(tc.name, func(t *testing.T) {
531 got := run(t, ClientIPFromHeader("X-Real-IP"), func(r *http.Request) {
684:23add-constantstring literal "garbage" appears more than twice; define a constant

middleware/client_ip_test.go:684:23

683 prefixes: []string{"10.0.0.0/8"},
684 xff: []string{"garbage", "203.0.113.7, 10.0.0.1"},
685 out: "203.0.113.7",

tree.go1

628:16cognitive-complexityfunction has cognitive complexity 19; maximum is 7

tree.go:628:16

627
628func (n *node) routes() []Route {
629 rts := []Route{}

middleware/strip_test.go1

61:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:61:3

60 w.WriteHeader(404)
61 w.Write([]byte("nothing here"))
62 })

middleware/heartbeat.go1

12:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/heartbeat.go:12:6

11// to place this above ACL middlewares as well.
12func Heartbeat(endpoint string) func(http.Handler) http.Handler {
13 f := func(h http.Handler) http.Handler {

middleware/route_headers_test.go1

1:1formatfile is not formatted

middleware/route_headers_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/route_headers_test.go`

tree.go1

473:8modifies-parameterassignment modifies parameter rctx

tree.go:473:8

472 if h != nil && h.handler != nil {
473 rctx.routeParams.Keys = append(rctx.routeParams.Keys, h.paramKeys...)
474 return xn

middleware/throttle_test.go1

267:20nested-structsmove nested anonymous struct types to named declarations

middleware/throttle_test.go:267:20

266
267 wait := make(chan struct{})
268

middleware/terminal.go1

29:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:29:2

28 bMagenta = []byte{'\033', '[', '3', '5', ';', '1', 'm'}
29 bCyan = []byte{'\033', '[', '3', '6', ';', '1', 'm'}
30 bWhite = []byte{'\033', '[', '3', '7', ';', '1', 'm'}

middleware/value.go1

1:9package-commentspackage should have a documentation comment

middleware/value.go:1:9

1package middleware
2

middleware/client_ip_test.go2

557:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:557:6

556// GetClientIP.
557func TestXFF_V4MappedIPv6BypassesTrustedV4Prefix(t *testing.T) {
558 tt := []struct {
685:14add-constantstring literal "203.0.113.7" appears more than twice; define a constant

middleware/client_ip_test.go:685:14

684 xff: []string{"garbage", "203.0.113.7, 10.0.0.1"},
685 out: "203.0.113.7",
686 },

tree.go1

695:6cognitive-complexityfunction has cognitive complexity 33; maximum is 7

tree.go:695:6

694// node type, param key, regexp string, param tail byte, param starting index, param ending index
695func patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) {
696 ps := strings.Index(pattern, "{")

middleware/strip_test.go1

65:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:65:3

64 r.Get("/hi", func(w http.ResponseWriter, r *http.Request) {
65 w.Write([]byte("hi"))
66 })

middleware/logger.go1

20:2exported-declaration-commentexported declaration should have a comment beginning with its name

middleware/logger.go:20:2

19 // logging configurations.
20 DefaultLogger func(next http.Handler) http.Handler
21)

middleware/strip_test.go1

1:1formatfile is not formatted

middleware/strip_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/strip_test.go`

tree.go1

481:8modifies-parameterassignment modifies parameter rctx

tree.go:481:8

480 }
481 rctx.methodsAllowed = append(rctx.methodsAllowed, endpoints)
482 }

mux_test.go1

643:17nested-structsmove nested anonymous struct types to named declarations

mux_test.go:643:17

642func TestMuxHandlePatternValidation(t *testing.T) {
643 testCases := []struct {
644 name string

middleware/terminal.go1

30:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:30:2

29 bCyan = []byte{'\033', '[', '3', '6', ';', '1', 'm'}
30 bWhite = []byte{'\033', '[', '3', '7', ';', '1', 'm'}
31

middleware/wrap_writer.go1

1:9package-commentspackage should have a documentation comment

middleware/wrap_writer.go:1:9

1package middleware
2

middleware/client_ip_test.go1

578:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:578:18

577 for _, tc := range tt {
578 t.Run(tc.name, func(t *testing.T) {
579 got := run(t, ClientIPFromXFF(tc.prefixes...), func(r *http.Request) {

middleware/compress_test.go1

40:34add-constantstring literal "text/html" appears more than twice; define a constant

middleware/compress_test.go:40:34

39 r.Get("/getcss", func(w http.ResponseWriter, r *http.Request) {
40 w.Header().Set("Content-Type", "text/html")
41 w.Write([]byte("textstring"))

tree.go1

763:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

tree.go:763:6

762
763func patParamKeys(pattern string) []string {
764 pat := pattern

middleware/strip_test.go1

71:4discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:71:4

70 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
71 w.Write([]byte("accounts index"))
72 })

middleware/logger.go1

39:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/logger.go:39:6

38// r.Get("/", handler)
39func Logger(next http.Handler) http.Handler {
40 return DefaultLogger(next)

middleware/sunset.go1

1:1formatfile is not formatted

middleware/sunset.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/sunset.go`

tree.go1

486:7modifies-parameterassignment modifies parameter rctx

tree.go:486:7

485 // supported method
486 rctx.methodNotAllowed = true
487 }

mux_test.go1

1348:17nested-structsmove nested anonymous struct types to named declarations

mux_test.go:1348:17

1347
1348 testcases := []struct {
1349 Ctx context.Context

middleware/terminal.go1

32:2no-package-varpackage variables introduce mutable global state

middleware/terminal.go:32:2

31
32 reset = []byte{'\033', '[', '0', 'm'}
33)

mux.go1

1:9package-commentspackage should have a documentation comment

mux.go:1:9

1package chi
2

middleware/client_ip_test.go1

599:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:599:6

598// and skipped.
599func TestXFF_IPv6ZoneIDBypassesTrustedV6Prefix(t *testing.T) {
600 got := run(t, ClientIPFromXFF("2606:4700::/32"), func(r *http.Request) {

middleware/compress_test.go1

45:18add-constantstring literal "Content-Type" appears more than twice; define a constant

middleware/compress_test.go:45:18

44 r.Get("/getplain", func(w http.ResponseWriter, r *http.Request) {
45 w.Header().Set("Content-Type", "text/html")
46 w.Write([]byte("textstring"))

tree.go1

846:6cognitive-complexityfunction has cognitive complexity 31; maximum is 7

tree.go:846:6

845
846func walk(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.Handler) http.Handler) error {
847 for _, route := range r.Routes() {

middleware/strip_test.go1

75:4discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:75:4

74 accountID := chi.URLParam(r, "accountID")
75 w.Write([]byte(accountID))
76 })

middleware/logger.go1

63:6exported-declaration-commentexported type should have a comment beginning with its name

middleware/logger.go:63:6

62// See DefaultLogFormatter for an example implementation.
63type LogFormatter interface {
64 NewLogEntry(r *http.Request) LogEntry

middleware/sunset_test.go1

1:1formatfile is not formatted

middleware/sunset_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/sunset_test.go`

tree.go1

497:5modifies-parameterassignment modifies parameter rctx

tree.go:497:5

496 // not found on this branch, reset vars
497 rctx.routeParams.Values = rctx.routeParams.Values[:prevlen]
498 xsearch = search

path_value_test.go1

11:17nested-structsmove nested anonymous struct types to named declarations

path_value_test.go:11:17

10func TestPathValue(t *testing.T) {
11 testCases := []struct {
12 name string

middleware/terminal.go1

35:5no-package-varpackage variables introduce mutable global state

middleware/terminal.go:35:5

34
35var IsTTY bool
36

tree.go1

1:9package-commentspackage should have a documentation comment

tree.go:1:9

1package chi
2

middleware/client_ip_test.go1

615:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:615:6

614// calls Unmap() before storing.
615func TestClientIPFromRemoteAddr_V4MappedIsUnmapped(t *testing.T) {
616 tt := []struct {

middleware/compress_test.go1

46:18add-constantstring literal "textstring" appears more than twice; define a constant

middleware/compress_test.go:46:18

45 w.Header().Set("Content-Type", "text/html")
46 w.Write([]byte("textstring"))
47 })

tree_test.go1

10:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

tree_test.go:10:6

9
10func TestTree(t *testing.T) {
11 hStub := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})

middleware/strip_test.go1

111:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:111:3

110 w.WriteHeader(404)
111 w.Write([]byte("nothing here"))
112 })

middleware/logger.go1

69:6exported-declaration-commentexported type should have a comment beginning with its name

middleware/logger.go:69:6

68// See defaultLogEntry for an example implementation.
69type LogEntry interface {
70 Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{})

middleware/supress_notfound.go1

1:1formatfile is not formatted

middleware/supress_notfound.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/supress_notfound.go`

tree.go1

501:4modifies-parameterassignment modifies parameter rctx

tree.go:501:4

500
501 rctx.routeParams.Values = append(rctx.routeParams.Values, "")
502

pattern_test.go1

10:17nested-structsmove nested anonymous struct types to named declarations

pattern_test.go:10:17

9func TestPattern(t *testing.T) {
10 testCases := []struct {
11 name string

middleware/throttle.go1

16:2no-package-varpackage variables introduce mutable global state

middleware/throttle.go:16:2

15var (
16 defaultBacklogTimeout = time.Second * 60
17)

middleware/client_ip_test.go1

625:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:625:18

624 for _, tc := range tt {
625 t.Run(tc.name, func(t *testing.T) {
626 got := run(t, ClientIPFromRemoteAddr, func(r *http.Request) {

middleware/compress_test.go1

72:23add-constantstring literal "/gethtml" appears more than twice; define a constant

middleware/compress_test.go:72:23

71 name: "gzip is only encoding",
72 path: "/gethtml",
73 acceptedEncodings: []string{"gzip"},

tree_test.go1

154:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

tree_test.go:154:6

153
154func TestTreeMoar(t *testing.T) {
155 hStub := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})

middleware/strip_test.go1

115:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:115:3

114 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
115 w.Write([]byte("root"))
116 })

middleware/logger.go1

168:27exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/logger.go:168:27

167
168func (l *defaultLogEntry) Panic(v interface{}, stack []byte) {
169 printPrettyStack(v, l.useColor)

middleware/terminal.go1

1:1formatfile is not formatted

middleware/terminal.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/terminal.go`

tree.go1

505:4modifies-parameterassignment modifies parameter rctx

tree.go:505:4

504 // catch-all nodes
505 rctx.routeParams.Values = append(rctx.routeParams.Values, search)
506 xn = nds[0]

tree_test.go1

80:13nested-structsmove nested anonymous struct types to named declarations

tree_test.go:80:13

79
80 tests := []struct {
81 r string // input request path

middleware/throttle_test.go1

15:5no-package-varpackage variables introduce mutable global state

middleware/throttle_test.go:15:5

14
15var testContent = []byte("Hello world!")
16

middleware/client_ip_test.go1

646:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/client_ip_test.go:646:6

645// by trim before parsing, and do not trip fail-closed.
646func TestXFF_FailClosedOnUnparseable(t *testing.T) {
647 tt := []struct {

middleware/compress_test.go1

79:32add-constantstring literal "gzip" appears more than twice; define a constant

middleware/compress_test.go:79:32

78 path: "/getcss",
79 acceptedEncodings: []string{"gzip", "deflate"},
80 expectedEncoding: "gzip",

tree_test.go1

270:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

tree_test.go:270:6

269
270func TestTreeRegexp(t *testing.T) {
271 hStub1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})

middleware/strip_test.go1

121:4discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:121:4

120 accountID := chi.URLParam(r, "accountID")
121 w.Write([]byte(accountID))
122 })

middleware/logger_test.go1

17:28exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/logger_test.go:17:28

16
17func (cw testLoggerWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
18 return nil, nil, nil

middleware/throttle.go1

1:1formatfile is not formatted

middleware/throttle.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/throttle.go`

tree.go1

519:6modifies-parameterassignment modifies parameter rctx

tree.go:519:6

518 if h != nil && h.handler != nil {
519 rctx.routeParams.Keys = append(rctx.routeParams.Keys, h.paramKeys...)
520 return xn

tree_test.go1

204:13nested-structsmove nested anonymous struct types to named declarations

tree_test.go:204:13

203
204 tests := []struct {
205 h http.Handler

middleware/url_format.go1

14:2no-package-varpackage variables introduce mutable global state

middleware/url_format.go:14:2

13 // for a request.
14 URLFormatCtxKey = &contextKey{"URLFormat"}
15)

middleware/client_ip_test.go1

689:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/client_ip_test.go:689:18

688 for _, tc := range tt {
689 t.Run(tc.name, func(t *testing.T) {
690 got := run(t, ClientIPFromXFF(tc.prefixes...), func(r *http.Request) {

middleware/compress_test.go1

84:23add-constantstring literal "/getcss" appears more than twice; define a constant

middleware/compress_test.go:84:23

83 name: "deflate is used",
84 path: "/getcss",
85 acceptedEncodings: []string{"deflate"},

tree_test.go1

336:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

tree_test.go:336:6

335
336func TestTreeRegexpRecursive(t *testing.T) {
337 hStub1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})

middleware/strip_test.go1

207:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:207:3

206 r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
207 w.Write([]byte("root"))
208 })

middleware/maybe.go1

8:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/maybe.go:8:6

7// a request does not satisfy the maybeFn logic.
8func Maybe(mw func(http.Handler) http.Handler, maybeFn func(r *http.Request) bool) func(http.Handler) http.Handler {
9 return func(next http.Handler) http.Handler {

middleware/throttle_test.go1

1:1formatfile is not formatted

middleware/throttle_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/throttle_test.go`

tree.go1

527:6modifies-parameterassignment modifies parameter rctx

tree.go:527:6

526 }
527 rctx.methodsAllowed = append(rctx.methodsAllowed, endpoints)
528 }

tree_test.go1

294:13nested-structsmove nested anonymous struct types to named declarations

tree_test.go:294:13

293
294 tests := []struct {
295 r string // input request path

tree.go1

33:5no-package-varpackage variables introduce mutable global state

tree.go:33:5

32
33var mALL = mCONNECT | mDELETE | mGET | mHEAD |
34 mOPTIONS | mPATCH | mPOST | mPUT | mQUERY | mTRACE

middleware/compress_test.go2

16:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/compress_test.go:16:6

15
16func TestCompressor(t *testing.T) {
17 r := chi.NewRouter()
86:23add-constantstring literal "deflate" appears more than twice; define a constant

middleware/compress_test.go:86:23

85 acceptedEncodings: []string{"deflate"},
86 expectedEncoding: "deflate",
87 },

tree_test.go1

447:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

tree_test.go:447:6

446
447func debugPrintTree(parent int, i int, n *node, label byte) bool {
448 numEdges := 0

middleware/strip_test.go1

211:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:211:3

210 r.HandleFunc("/accounts", func(w http.ResponseWriter, r *http.Request) {
211 w.Write([]byte("accounts"))
212 })

middleware/nocache.go1

40:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/nocache.go:40:6

39// Pragma: no-cache (for HTTP/1.0 proxies/clients)
40func NoCache(h http.Handler) http.Handler {
41 fn := func(w http.ResponseWriter, r *http.Request) {

middleware/url_format.go1

1:1formatfile is not formatted

middleware/url_format.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/url_format.go`

tree.go1

532:5modifies-parameterassignment modifies parameter rctx

tree.go:532:5

531 // supported method
532 rctx.methodNotAllowed = true
533 }

tree_test.go1

350:13nested-structsmove nested anonymous struct types to named declarations

tree_test.go:350:13

349
350 tests := []struct {
351 r string // input request path

tree.go1

41:5no-package-varpackage variables introduce mutable global state

tree.go:41:5

40
41var methodMap = map[string]methodTyp{
42 http.MethodConnect: mCONNECT,

middleware/compress_test.go1

98:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/compress_test.go:98:18

97 for _, tc := range tests {
98 t.Run(tc.name, func(t *testing.T) {
99 resp, respString := testRequestWithAcceptedEncodings(t, ts, "GET", tc.path, tc.acceptedEncodings...)

middleware/content_charset_test.go1

124:69add-constantstring literal "utf-8" appears more than twice; define a constant

middleware/content_charset_test.go:124:69

123
124 if !contentEncoding("text/xml; charset=UTF-8", []string{"latin-1", "utf-8"}...) {
125 t.Error("Want true, got false")

middleware/strip_test.go1

215:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:215:3

214 r.HandleFunc("/accounts/admin", func(w http.ResponseWriter, r *http.Request) {
215 w.Write([]byte("admin"))
216 })

middleware/page_route.go1

10:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/page_route.go:10:6

9// at the middleware stack level.
10func PageRoute(path string, handler http.Handler) func(http.Handler) http.Handler {
11 return func(next http.Handler) http.Handler {

middleware/url_format_test.go1

1:1formatfile is not formatted

middleware/url_format_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/url_format_test.go`

tree.go1

545:5modifies-parameterassignment modifies parameter rctx

tree.go:545:5

544 if len(rctx.routeParams.Values) > 0 {
545 rctx.routeParams.Values = rctx.routeParams.Values[:len(rctx.routeParams.Values)-1]
546 }

tree_test.go1

396:13nested-structsmove nested anonymous struct types to named declarations

tree_test.go:396:13

395
396 tests := []struct {
397 expectedHandler http.Handler

tree.go1

54:5no-package-varpackage variables introduce mutable global state

tree.go:54:5

53
54var reverseMethodMap = map[methodTyp]string{
55 mCONNECT: http.MethodConnect,

middleware/compress_test.go1

112:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/compress_test.go:112:6

111
112func TestCompressorWildcards(t *testing.T) {
113 tests := []struct {

middleware/content_encoding_test.go1

44:29add-constantstring literal "gzip" appears more than twice; define a constant

middleware/content_encoding_test.go:44:29

43 name: "Support for gzip and deflate encoding",
44 encodings: []string{"gzip", "deflate"},
45 expectedStatus: 200,

middleware/strip_test.go1

247:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:247:3

246 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
247 w.Write([]byte("api root"))
248 })

middleware/profiler.go1

22:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/profiler.go:22:6

21// }
22func Profiler() http.Handler {
23 r := chi.NewRouter()

middleware/wrap_writer.go1

1:1formatfile is not formatted

middleware/wrap_writer.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/wrap_writer.go`

tree_test.go2

463:2modifies-parameterassignment modifies parameter parent

tree_test.go:463:2

462 }
463 parent = i
464 for _, nds := range n.children {
529:13nested-structsmove nested anonymous struct types to named declarations

tree_test.go:529:13

528
529 tests := []struct {
530 name string

middleware/compress_test.go1

152:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/compress_test.go:152:18

151 for _, tt := range tests {
152 t.Run(tt.name, func(t *testing.T) {
153 defer func() {

middleware/content_encoding_test.go1

49:29add-constantstring literal "deflate" appears more than twice; define a constant

middleware/content_encoding_test.go:49:29

48 name: "Support for deflate and gzip encoding",
49 encodings: []string{"deflate", "gzip"},
50 expectedStatus: 200,

middleware/strip_test.go1

251:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:251:3

250 r.Get("/accounts", func(w http.ResponseWriter, r *http.Request) {
251 w.Write([]byte("api accounts"))
252 })

middleware/realip.go1

28:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/realip.go:28:6

27// These never mutate r.RemoteAddr.
28func RealIP(h http.Handler) http.Handler {
29 fn := func(w http.ResponseWriter, r *http.Request) {

middleware/wrap_writer_test.go1

1:1formatfile is not formatted

middleware/wrap_writer_test.go:1:1

1package middleware
2
  • Fix (safe): run `strider fmt middleware/wrap_writer_test.go`

tree_test.go1

466:4modifies-parameterassignment modifies parameter i

tree_test.go:466:4

465 for _, e := range nds {
466 i++
467 if debugPrintTree(parent, i, e, e.label) {

middleware/get_head_test.go2

11:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/get_head_test.go:11:6

10
11func TestGetHead(t *testing.T) {
12 r := chi.NewRouter()
30:9add-constantstring literal "/{id}" appears more than twice; define a constant

middleware/get_head_test.go:30:9

29 })
30 r.Get("/{id}", func(w http.ResponseWriter, r *http.Request) {
31 id := chi.URLParam(r, "id")

middleware/strip_test.go1

256:3discarded-error-resulterror result returned by w.Write is discarded

middleware/strip_test.go:256:3

255 accountID := chi.URLParam(r, "accountID")
256 w.Write([]byte(accountID))
257 })

middleware/recoverer.go1

22:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/recoverer.go:22:6

21// Alternatively, look at https://github.com/go-chi/httplog middleware pkgs.
22func Recoverer(next http.Handler) http.Handler {
23 fn := func(w http.ResponseWriter, r *http.Request) {

mux.go1

1:1formatfile is not formatted

mux.go:1:1

1package chi
2
  • Fix (safe): run `strider fmt mux.go`

middleware/logger_test.go1

21:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/logger_test.go:21:6

20
21func TestRequestLogger(t *testing.T) {
22 testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

middleware/get_head_test.go1

43:45add-constantstring literal "/hi" appears more than twice; define a constant

middleware/get_head_test.go:43:45

42 }
43 if req, body := testRequest(t, ts, "HEAD", "/hi", nil); body != "" || req.Header.Get("X-Test") != "yes" {
44 t.Fatal(body)

middleware/sunset_test.go1

15:13discarded-error-resulterror result returned by http.NewRequest is discarded

middleware/sunset_test.go:15:13

14 t.Run("Sunset without link", func(t *testing.T) {
15 req, _ := http.NewRequest("GET", "/", nil)
16 w := httptest.NewRecorder()

middleware/recoverer.go1

54:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/recoverer.go:54:6

53
54func PrintPrettyStack(rvr interface{}) {
55 printPrettyStack(rvr, true)

mux_test.go1

1:1formatfile is not formatted

mux_test.go:1:1

1package chi
2
  • Fix (safe): run `strider fmt mux_test.go`

middleware/logger_test.go1

38:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/logger_test.go:38:6

37
38func TestRequestLoggerReadFrom(t *testing.T) {
39 data := []byte("file data")

middleware/get_head_test.go1

53:35add-constantstring literal "GET" appears more than twice; define a constant

middleware/get_head_test.go:53:35

52
53 if _, body := testRequest(t, ts, "GET", "/articles/5", nil); body != "article:5" {
54 t.Fatal(body)

middleware/sunset_test.go1

28:4discarded-error-resulterror result returned by w.Write is discarded

middleware/sunset_test.go:28:4

27 deprecation = clonedHeader.Get("Deprecation")
28 w.Write([]byte("I'll be unavailable soon"))
29 })

middleware/recoverer_test.go1

17:24exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/recoverer_test.go:17:24

16
17func (testPrintLogger) Print(v ...interface{}) {}
18

path_value_test.go1

1:1formatfile is not formatted

path_value_test.go:1:1

1package chi
2
  • Fix (safe): run `strider fmt path_value_test.go`

middleware/middleware_test.go1

22:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/middleware_test.go:22:6

21
22func TestWrapWriterHTTP2(t *testing.T) {
23 handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

middleware/get_head_test.go1

56:37add-constantstring literal "HEAD" appears more than twice; define a constant

middleware/get_head_test.go:56:37

55 }
56 if req, body := testRequest(t, ts, "HEAD", "/articles/5", nil); body != "" || req.Header.Get("X-Article") != "5" {
57 t.Fatalf("expecting X-Article header '5' but got '%s'", req.Header.Get("X-Article"))

middleware/sunset_test.go1

46:13discarded-error-resulterror result returned by http.NewRequest is discarded

middleware/sunset_test.go:46:13

45 t.Run("Sunset with link", func(t *testing.T) {
46 req, _ := http.NewRequest("GET", "/", nil)
47 w := httptest.NewRecorder()

middleware/request_id.go1

25:5exported-declaration-commentexported declaration should have a comment beginning with its name

middleware/request_id.go:25:5

24// Exported so that it can be changed by developers
25var RequestIDHeader = "X-Request-Id"
26

pattern_test.go1

1:1formatfile is not formatted

pattern_test.go:1:1

1package chi
2
  • Fix (safe): run `strider fmt pattern_test.go`

middleware/realip_test.go1

11:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/realip_test.go:11:6

10
11func TestXRealIP(t *testing.T) {
12 req, _ := http.NewRequest("GET", "/", nil)

middleware/get_head_test.go1

57:74add-constantstring literal "X-Article" appears more than twice; define a constant

middleware/get_head_test.go:57:74

56 if req, body := testRequest(t, ts, "HEAD", "/articles/5", nil); body != "" || req.Header.Get("X-Article") != "5" {
57 t.Fatalf("expecting X-Article header '5' but got '%s'", req.Header.Get("X-Article"))
58 }

middleware/sunset_test.go1

62:4discarded-error-resulterror result returned by w.Write is discarded

middleware/sunset_test.go:62:4

61
62 w.Write([]byte("I'll be unavailable soon"))
63 })

middleware/request_id.go1

67:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/request_id.go:67:6

66// counter.
67func RequestID(next http.Handler) http.Handler {
68 fn := func(w http.ResponseWriter, r *http.Request) {

tree.go1

1:1formatfile is not formatted

tree.go:1:1

1package chi
2
  • Fix (safe): run `strider fmt tree.go`

middleware/realip_test.go1

35:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/realip_test.go:35:6

34
35func TestXForwardForIP(t *testing.T) {
36 xForwardedForIPs := []string{

middleware/get_head_test.go1

63:92add-constantstring literal "X-User" appears more than twice; define a constant

middleware/get_head_test.go:63:92

62 }
63 if req, body := testRequest(t, ts, "HEAD", "/users/1", nil); body != "" || req.Header.Get("X-User") != "-" {
64 t.Fatalf("expecting X-User header '-' but got '%s'", req.Header.Get("X-User"))

middleware/terminal.go1

57:3discarded-error-resulterror result returned by w.Write is discarded

middleware/terminal.go:57:3

56 if IsTTY && useColor {
57 w.Write(color)
58 }

middleware/request_id.go1

83:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/request_id.go:83:6

82// Returns the empty string if a request ID cannot be found.
83func GetReqID(ctx context.Context) string {
84 if ctx == nil {

tree_test.go1

1:1formatfile is not formatted

tree_test.go:1:1

1package chi
2
  • Fix (safe): run `strider fmt tree_test.go`

middleware/realip_test.go1

68:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/realip_test.go:68:6

67
68func TestXForwardForXRealIPPrecedence(t *testing.T) {
69 req, _ := http.NewRequest("GET", "/", nil)

middleware/logger.go1

147:32add-constantstring literal "%03d" appears more than twice; define a constant

middleware/logger.go:147:32

146 case status < 400:
147 cW(l.buf, l.useColor, bCyan, "%03d", status)
148 case status < 500:

middleware/terminal.go1

61:3discarded-error-resulterror result returned by w.Write is discarded

middleware/terminal.go:61:3

60 if IsTTY && useColor {
61 w.Write(reset)
62 }

middleware/request_size.go1

9:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/request_size.go:9:6

8// number of bytes. It uses MaxBytesReader to do so.
9func RequestSize(bytes int64) func(http.Handler) http.Handler {
10 f := func(h http.Handler) http.Handler {

middleware/realip_test.go1

93:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/realip_test.go:93:6

92
93func TestInvalidIP(t *testing.T) {
94 req, _ := http.NewRequest("GET", "/", nil)

middleware/logger.go1

162:31add-constantstring literal "%s" appears more than twice; define a constant

middleware/logger.go:162:31

161 } else {
162 cW(l.buf, l.useColor, nRed, "%s", elapsed)
163 }

middleware/throttle_test.go1

25:3discarded-error-resulterror result returned by w.Write is discarded

middleware/throttle_test.go:25:3

24 time.Sleep(time.Second * 1) // Expensive operation.
25 w.Write(testContent)
26 })

middleware/route_headers.go1

42:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/route_headers.go:42:6

41// Handler)
42func RouteHeaders() HeaderRouter {
43 return HeaderRouter{}

middleware/recoverer_test.go1

78:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/recoverer_test.go:78:6

77
78func TestRecovererAbortHandler(t *testing.T) {
79 defer func() {

middleware/realip_test.go1

37:3add-constantstring literal "100.100.100.100" appears more than twice; define a constant

middleware/realip_test.go:37:3

36 xForwardedForIPs := []string{
37 "100.100.100.100",
38 "100.100.100.100, 200.200.200.200",

middleware/throttle_test.go1

66:3discarded-error-resulterror result returned by w.Write is discarded

middleware/throttle_test.go:66:3

65 time.Sleep(time.Second * 5) // Expensive operation.
66 w.Write(testContent)
67 })

middleware/route_headers.go1

46:6exported-declaration-commentexported type should have a comment beginning with its name

middleware/route_headers.go:46:6

45
46type HeaderRouter map[string][]HeaderRoute
47

middleware/route_headers_test.go1

10:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/route_headers_test.go:10:6

9
10func TestRouteHeaders(t *testing.T) {
11 t.Run("empty router should call next handler exactly once", func(t *testing.T) {

middleware/realip_test.go1

46:36add-constantstring literal "/" appears more than twice; define a constant

middleware/realip_test.go:46:36

45 for _, v := range xForwardedForIPs {
46 req, _ := http.NewRequest("GET", "/", nil)
47 req.Header.Add("X-Forwarded-For", v)

middleware/throttle_test.go1

98:3discarded-error-resulterror result returned by w.Write is discarded

middleware/throttle_test.go:98:3

97 time.Sleep(time.Second * 10) // Expensive operation.
98 w.Write(testContent)
99 })

middleware/route_headers.go1

48:24exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/route_headers.go:48:24

47
48func (hr HeaderRouter) Route(header, match string, middlewareHandler func(next http.Handler) http.Handler) HeaderRouter {
49 header = strings.ToLower(header)

middleware/route_headers_test.go1

11:62test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/route_headers_test.go:11:62

10func TestRouteHeaders(t *testing.T) {
11 t.Run("empty router should call next handler exactly once", func(t *testing.T) {
12 var callCount atomic.Int32

middleware/realip_test.go1

69:28add-constantstring literal "GET" appears more than twice; define a constant

middleware/realip_test.go:69:28

68func TestXForwardForXRealIPPrecedence(t *testing.T) {
69 req, _ := http.NewRequest("GET", "/", nil)
70 req.Header.Add("X-Forwarded-For", "0.0.0.0")

middleware/throttle_test.go1

152:3discarded-error-resulterror result returned by w.Write is discarded

middleware/throttle_test.go:152:3

151 time.Sleep(time.Second * 3) // Expensive operation.
152 w.Write(testContent)
153 })

middleware/route_headers.go1

58:24exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/route_headers.go:58:24

57
58func (hr HeaderRouter) RouteAny(header string, match []string, middlewareHandler func(next http.Handler) http.Handler) HeaderRouter {
59 header = strings.ToLower(header)

middleware/route_headers_test.go1

31:62test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/route_headers_test.go:31:62

30
31 t.Run("matching header should route to correct middleware", func(t *testing.T) {
32 var matchedRoute string

middleware/realip_test.go1

80:18add-constantstring literal "Hello World" appears more than twice; define a constant

middleware/realip_test.go:80:18

79 realIP = r.RemoteAddr
80 w.Write([]byte("Hello World"))
81 })

middleware/throttle_test.go1

215:3discarded-error-resulterror result returned by w.Write is discarded

middleware/throttle_test.go:215:3

214 w.WriteHeader(http.StatusOK)
215 w.Write([]byte("ok"))
216 })

middleware/route_headers.go1

72:24exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/route_headers.go:72:24

71
72func (hr HeaderRouter) RouteDefault(handler func(next http.Handler) http.Handler) HeaderRouter {
73 hr["*"] = []HeaderRoute{{Middleware: handler}}

middleware/route_headers_test.go1

64:41test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/route_headers_test.go:64:41

63
64 t.Run("wildcard pattern should match", func(t *testing.T) {
65 var matched bool

middleware/realip_test.go1

85:11add-constantstring literal "Response Code should be 200" appears more than twice; define a constant

middleware/realip_test.go:85:11

84 if w.Code != 200 {
85 t.Fatal("Response Code should be 200")
86 }

middleware/throttle_test.go1

235:14discarded-error-resulterror result returned by client.Get is discarded

middleware/throttle_test.go:235:14

234 defer wg.Done()
235 res, _ := client.Get(server.URL)
236 resultsCh <- result{status: res.StatusCode, header: res.Header}

middleware/route_headers.go1

77:24exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/route_headers.go:77:24

76
77func (hr HeaderRouter) Handler(next http.Handler) http.Handler {
78 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

middleware/route_headers_test.go1

90:54test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/route_headers_test.go:90:54

89
90 t.Run("default route should be used when no match", func(t *testing.T) {
91 var usedDefault bool

middleware/realip_test.go1

95:17add-constantstring literal "X-Real-IP" appears more than twice; define a constant

middleware/realip_test.go:95:17

94 req, _ := http.NewRequest("GET", "/", nil)
95 req.Header.Add("X-Real-IP", "100.100.100.1000")
96 w := httptest.NewRecorder()

middleware/url_format_test.go1

18:3discarded-error-resulterror result returned by w.Write is discarded

middleware/url_format_test.go:18:3

17 w.WriteHeader(404)
18 w.Write([]byte("nothing here"))
19 })

middleware/route_headers.go1

110:6exported-declaration-commentexported type should have a comment beginning with its name

middleware/route_headers.go:110:6

109
110type HeaderRoute struct {
111 Middleware func(next http.Handler) http.Handler

middleware/route_headers_test.go1

121:62test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/route_headers_test.go:121:62

120
121 t.Run("RouteAny should match any of the provided patterns", func(t *testing.T) {
122 var matched bool

middleware/recoverer.go1

127:32add-constantstring literal "\t" appears more than twice; define a constant

middleware/recoverer.go:127:32

126 if strings.HasPrefix(line, "\t") {
127 return strings.Replace(line, "\t", " ", 1), nil
128 }

middleware/url_format_test.go1

24:4discarded-error-resulterror result returned by w.Write is discarded

middleware/url_format_test.go:24:4

23 articleID := chi.URLParam(r, "articleID")
24 w.Write([]byte(articleID))
25 })

middleware/route_headers.go1

116:22exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/route_headers.go:116:22

115
116func (r HeaderRoute) IsMatch(value string) bool {
117 if len(r.MatchAny) > 0 {

middleware/route_headers_test.go1

160:60test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/route_headers_test.go:160:60

159
160 t.Run("no match and no default should call next handler", func(t *testing.T) {
161 var nextCalled bool

middleware/recoverer.go1

200:28add-constantstring literal "%s" appears more than twice; define a constant

middleware/recoverer.go:200:28

199 }
200 cW(buf, useColor, bWhite, "%s", dir)
201 cW(buf, useColor, fileColor, "%s", file)

middleware/url_format_test.go1

31:4discarded-error-resulterror result returned by w.Write is discarded

middleware/url_format_test.go:31:4

30 articleID := chi.URLParam(r, "articleID")
31 w.Write([]byte(articleID))
32 })

middleware/route_headers.go1

129:6exported-declaration-commentexported type should have a comment beginning with its name

middleware/route_headers.go:129:6

128
129type Pattern struct {
130 prefix string

middleware/route_headers_test.go1

187:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/route_headers_test.go:187:6

186
187func TestPattern(t *testing.T) {
188 tests := []struct {

middleware/recoverer.go1

204:26add-constantstring literal "\n" appears more than twice; define a constant

middleware/recoverer.go:204:26

203 if num == 1 {
204 cW(buf, false, bWhite, "\n")
205 }

middleware/url_format_test.go1

59:4discarded-error-resulterror result returned by w.Write is discarded

middleware/url_format_test.go:59:4

58 articleID := chi.URLParam(r, "articleID")
59 w.Write([]byte(articleID))
60 })

middleware/route_headers.go1

135:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/route_headers.go:135:6

134
135func NewPattern(value string) Pattern {
136 p := Pattern{}

middleware/route_headers_test.go1

205:34test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/route_headers_test.go:205:34

204 for _, tt := range tests {
205 t.Run(tt.pattern+"_"+tt.value, func(t *testing.T) {
206 p := NewPattern(tt.pattern)

middleware/recoverer_test.go1

64:8add-constantstring literal "/" appears more than twice; define a constant

middleware/recoverer_test.go:64:8

63 r.Use(Recoverer)
64 r.Get("/", panickingHandler)
65

mux.go1

530:3discarded-error-resulterror result returned by w.Write is discarded

mux.go:530:3

529 w.WriteHeader(405)
530 w.Write(nil)
531 }

middleware/route_headers.go1

141:18exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/route_headers.go:141:18

140
141func (p Pattern) Match(v string) bool {
142 if !p.wildcard {

middleware/strip_test.go1

13:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/strip_test.go:13:6

12
13func TestStripSlashes(t *testing.T) {
14 r := chi.NewRouter()

middleware/recoverer_test.go1

95:30add-constantstring literal "GET" appears more than twice; define a constant

middleware/recoverer_test.go:95:30

94
95 req, err := http.NewRequest("GET", "/", nil)
96 if err != nil {

mux_test.go1

55:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:55:3

54 w.WriteHeader(200)
55 w.Write([]byte(fmt.Sprintf("hi %s", user)))
56 }

middleware/strip.go1

14:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/strip.go:14:6

13// matches, then it will serve the handler.
14func StripSlashes(next http.Handler) http.Handler {
15 fn := func(w http.ResponseWriter, r *http.Request) {

middleware/strip_test.go1

56:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/strip_test.go:56:6

55
56func TestStripSlashesInRoute(t *testing.T) {
57 r := chi.NewRouter()

middleware/request_id_test.go1

59:9add-constantstring literal "/" appears more than twice; define a constant

middleware/request_id_test.go:59:9

58
59 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
60 requestID := GetReqID(r.Context())

mux_test.go1

60:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:60:3

59 w.WriteHeader(200)
60 w.Write([]byte("."))
61 }

middleware/strip.go1

41:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/strip.go:41:6

40// see https://github.com/go-chi/chi/issues/343
41func RedirectSlashes(next http.Handler) http.Handler {
42 fn := func(w http.ResponseWriter, r *http.Request) {

middleware/strip_test.go1

102:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/strip_test.go:102:6

101
102func TestRedirectSlashes(t *testing.T) {
103 r := chi.NewRouter()

middleware/route_headers.go1

137:54add-constantstring literal "*" appears more than twice; define a constant

middleware/route_headers.go:137:54

136 p := Pattern{}
137 p.prefix, p.suffix, p.wildcard = strings.Cut(value, "*")
138 return p

mux_test.go1

75:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:75:3

74 w.WriteHeader(200)
75 w.Write([]byte("ping all"))
76 }

middleware/strip.go1

73:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/strip.go:73:6

72// request path before handing the request over to the next handler.
73func StripPrefix(prefix string) func(http.Handler) http.Handler {
74 return func(next http.Handler) http.Handler {

middleware/strip_test.go1

203:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/strip_test.go:203:6

202// In these cases, the routeContext is nil
203func TestStripSlashesWithNilContext(t *testing.T) {
204 r := http.NewServeMux()

middleware/route_headers_test.go1

53:14add-constantstring literal "example.com" appears more than twice; define a constant

middleware/route_headers_test.go:53:14

52 req := httptest.NewRequest("GET", "/", nil)
53 req.Host = "example.com"
54 req.Header.Set("Host", "example.com")

mux_test.go1

80:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:80:3

79 w.WriteHeader(200)
80 w.Write([]byte("ping all2"))
81 }

middleware/sunset.go1

11:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/sunset.go:11:6

10// For more: https://www.rfc-editor.org/rfc/rfc8594.html
11func Sunset(sunsetAt time.Time, links ...string) func(http.Handler) http.Handler {
12 return func(next http.Handler) http.Handler {

middleware/strip_test.go1

241:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/strip_test.go:241:6

240
241func TestStripPrefix(t *testing.T) {
242 r := chi.NewRouter()

middleware/route_headers_test.go1

54:18add-constantstring literal "Host" appears more than twice; define a constant

middleware/route_headers_test.go:54:18

53 req.Host = "example.com"
54 req.Header.Set("Host", "example.com")
55 rec := httptest.NewRecorder()

mux_test.go1

86:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:86:3

85 w.WriteHeader(200)
86 w.Write([]byte(fmt.Sprintf("ping one id: %s", idParam)))
87 }

middleware/supress_notfound.go1

15:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/supress_notfound.go:15:6

14// example its super annoying to see a bunch of 404's in your logs from bots.
15func SupressNotFound(router *chi.Mux) func(next http.Handler) http.Handler {
16 return func(next http.Handler) http.Handler {

middleware/strip_test.go1

276:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/strip_test.go:276:6

275
276func TestRedirectSlashes_PreventBackslashRelativeOpenRedirect(t *testing.T) {
277 h := RedirectSlashes(http.NotFoundHandler())

middleware/route_headers_test.go1

79:30add-constantstring literal "GET" appears more than twice; define a constant

middleware/route_headers_test.go:79:30

78
79 req := httptest.NewRequest("GET", "/", nil)
80 req.Header.Set("Host", "api.example.com")

mux_test.go1

91:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:91:3

90 w.WriteHeader(200)
91 w.Write([]byte("woop." + URLParam(r, "iidd")))
92 }

middleware/terminal.go1

35:5exported-declaration-commentexported declaration should have a comment beginning with its name

middleware/terminal.go:35:5

34
35var IsTTY bool
36

middleware/strip_test.go1

294:18test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/strip_test.go:294:18

293 for _, tc := range tests {
294 t.Run(tc.name, func(t *testing.T) {
295 req := httptest.NewRequest(http.MethodGet, "http://example.test"+tc.target, nil)

middleware/route_headers_test.go1

79:37add-constantstring literal "/" appears more than twice; define a constant

middleware/route_headers_test.go:79:37

78
79 req := httptest.NewRequest("GET", "/", nil)
80 req.Header.Set("Host", "api.example.com")

mux_test.go1

96:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:96:3

95 w.WriteHeader(200)
96 w.Write([]byte("catchall"))
97 }

middleware/throttle.go1

32:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/throttle.go:32:6

31// being processed from the point from where the Throttle middleware is mounted.
32func Throttle(limit int) func(http.Handler) http.Handler {
33 return ThrottleWithOpts(ThrottleOpts{Limit: limit, BacklogTimeout: defaultBacklogTimeout})

middleware/sunset_test.go1

12:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/sunset_test.go:12:6

11
12func TestSunset(t *testing.T) {
13

middleware/route_headers_test.go1

111:26add-constantstring literal "other.com" appears more than twice; define a constant

middleware/route_headers_test.go:111:26

110 req := httptest.NewRequest("GET", "/", nil)
111 req.Header.Set("Host", "other.com")
112 rec := httptest.NewRecorder()

mux_test.go1

213:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:213:3

212 v := URLParam(r, "hash")
213 w.Write([]byte(fmt.Sprintf("/%s", v)))
214 })

middleware/throttle.go1

39:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/throttle.go:39:6

38// pending requests.
39func ThrottleBacklog(limit, backlogLimit int, backlogTimeout time.Duration) func(http.Handler) http.Handler {
40 return ThrottleWithOpts(ThrottleOpts{Limit: limit, BacklogLimit: backlogLimit, BacklogTimeout: backlogTimeout})

middleware/sunset_test.go1

14:31test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/sunset_test.go:14:31

13
14 t.Run("Sunset without link", func(t *testing.T) {
15 req, _ := http.NewRequest("GET", "/", nil)

middleware/route_headers_test.go1

150:18add-constantstring literal "Content-Type" appears more than twice; define a constant

middleware/route_headers_test.go:150:18

149 req = httptest.NewRequest("POST", "/", nil)
150 req.Header.Set("Content-Type", "application/xml")
151 rec = httptest.NewRecorder()

mux_test.go1

219:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:219:4

218 v := URLParam(r, "hash")
219 w.Write([]byte(fmt.Sprintf("/%s/share", v)))
220 })

middleware/timeout.go1

32:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/timeout.go:32:6

31// })
32func Timeout(timeout time.Duration) func(next http.Handler) http.Handler {
33 return func(next http.Handler) http.Handler {

middleware/sunset_test.go1

45:28test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/sunset_test.go:45:28

44
45 t.Run("Sunset with link", func(t *testing.T) {
46 req, _ := http.NewRequest("GET", "/", nil)

middleware/route_headers_test.go1

196:4add-constantstring literal "*.example.com" appears more than twice; define a constant

middleware/route_headers_test.go:196:4

195 {"*.example.com", "api.example.com", true},
196 {"*.example.com", "example.com", false},
197 {"api.*", "api.example.com", true},

mux_test.go1

224:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:224:4

223 n := URLParam(r, "network")
224 w.Write([]byte(fmt.Sprintf("/%s/share/%s", v, n)))
225 })

middleware/url_format.go1

14:2exported-declaration-commentexported declaration should have a comment beginning with its name

middleware/url_format.go:14:2

13 // for a request.
14 URLFormatCtxKey = &contextKey{"URLFormat"}
15)

middleware/throttle_test.go1

17:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/throttle_test.go:17:6

16
17func TestThrottleBacklog(t *testing.T) {
18 r := chi.NewRouter()

middleware/route_headers_test.go1

197:13add-constantstring literal "api.example.com" appears more than twice; define a constant

middleware/route_headers_test.go:197:13

196 {"*.example.com", "example.com", false},
197 {"api.*", "api.example.com", true},
198 {"*", "anything", true},

mux_test.go1

248:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:248:3

247 r.Get("/hi", func(w http.ResponseWriter, r *http.Request) {
248 w.Write([]byte("bye"))
249 })

middleware/url_format.go1

46:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/url_format.go:46:6

45// }
46func URLFormat(next http.Handler) http.Handler {
47 fn := func(w http.ResponseWriter, r *http.Request) {

middleware/throttle_test.go1

58:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/throttle_test.go:58:6

57
58func TestThrottleClientTimeout(t *testing.T) {
59 r := chi.NewRouter()

middleware/route_headers_test.go1

201:4add-constantstring literal "prefix*suffix" appears more than twice; define a constant

middleware/route_headers_test.go:201:4

200 {"prefix*suffix", "prefixsuffix", true},
201 {"prefix*suffix", "wrongmiddlesuffix", false},
202 }

mux_test.go1

252:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:252:3

251 w.WriteHeader(404)
252 w.Write([]byte("nothing here"))
253 })

middleware/wrap_writer.go1

15:6exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:15:6

14// hook into various parts of the response process.
15func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter {
16 _, fl := w.(http.Flusher)

middleware/throttle_test.go1

90:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/throttle_test.go:90:6

89
90func TestThrottleTriggerGatewayTimeout(t *testing.T) {
91 r := chi.NewRouter()

middleware/strip_test.go1

39:42add-constantstring literal "/" appears more than twice; define a constant

middleware/strip_test.go:39:42

38
39 if _, resp := testRequest(t, ts, "GET", "/", nil); resp != "root" {
40 t.Fatal(resp)

mux_test.go1

289:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:289:3

288 w.WriteHeader(404)
289 w.Write([]byte("nothing here"))
290 })

middleware/wrap_writer.go1

48:6exported-declaration-commentexported type should have a comment beginning with its name

middleware/wrap_writer.go:48:6

47// into various parts of the response process.
48type WrapResponseWriter interface {
49 http.ResponseWriter

middleware/throttle_test.go1

144:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/throttle_test.go:144:6

143
144func TestThrottleMaximum(t *testing.T) {
145 r := chi.NewRouter()

middleware/strip_test.go1

42:62add-constantstring literal "root" appears more than twice; define a constant

middleware/strip_test.go:42:62

41 }
42 if _, resp := testRequest(t, ts, "GET", "//", nil); resp != "root" {
43 t.Fatal(resp)

mux_test.go1

295:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:295:3

294 accountID := URLParam(r, "accountID")
295 w.Write([]byte(accountID))
296 }

middleware/wrap_writer.go1

82:23exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:82:23

81
82func (b *basicWriter) WriteHeader(code int) {
83 if code >= 100 && code <= 199 && code != http.StatusSwitchingProtocols {

middleware/throttle_test.go1

202:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/throttle_test.go:202:6

201
202func TestThrottleRetryAfter(t *testing.T) {
203 r := chi.NewRouter()

middleware/strip_test.go1

45:35add-constantstring literal "GET" appears more than twice; define a constant

middleware/strip_test.go:45:35

44 }
45 if _, resp := testRequest(t, ts, "GET", "/accounts/admin", nil); resp != "admin" {
46 t.Fatal(resp)

mux_test.go1

327:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:327:3

326 r.Get("/hi", func(w http.ResponseWriter, r *http.Request) {
327 w.Write([]byte("bye"))
328 })

middleware/wrap_writer.go1

122:23exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:122:23

121
122func (b *basicWriter) Status() int {
123 return b.code

middleware/throttle_test.go1

264:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/throttle_test.go:264:6

263
264func TestThrottleCustomStatusCode(t *testing.T) {
265 const timeout = time.Second * 3

middleware/strip_test.go1

61:18add-constantstring literal "nothing here" appears more than twice; define a constant

middleware/strip_test.go:61:18

60 w.WriteHeader(404)
61 w.Write([]byte("nothing here"))
62 })

mux_test.go1

339:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:339:3

338 w.WriteHeader(404)
339 w.Write([]byte(fmt.Sprintf("root 404 %s %s", chkMw, chkWith)))
340 })

middleware/wrap_writer.go1

126:23exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:126:23

125
126func (b *basicWriter) BytesWritten() int {
127 return b.bytes

middleware/url_format_test.go1

11:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/url_format_test.go:11:6

10
11func TestURLFormat(t *testing.T) {
12 r := chi.NewRouter()

middleware/strip_test.go1

91:76add-constantstring literal "accounts index" appears more than twice; define a constant

middleware/strip_test.go:91:76

90 }
91 if _, resp := testRequest(t, ts, "GET", "/accounts/admin/", nil); resp != "accounts index" {
92 t.Fatal(resp)

mux_test.go1

345:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:345:3

344 sr1.Get("/sub", func(w http.ResponseWriter, r *http.Request) {
345 w.Write([]byte("sub"))
346 })

middleware/wrap_writer.go1

130:23exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:130:23

129
130func (b *basicWriter) Tee(w io.Writer) {
131 b.tee = w

middleware/url_format_test.go1

52:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/url_format_test.go:52:6

51
52func TestURLFormatInSubRouter(t *testing.T) {
53 r := chi.NewRouter()

middleware/strip_test.go1

94:81add-constantstring literal "admin" appears more than twice; define a constant

middleware/strip_test.go:94:81

93 }
94 if _, resp := testRequest(t, ts, "GET", "/accounts/admin/query", nil); resp != "admin" {
95 t.Fatal(resp)

mux_test.go1

357:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:357:4

356 w.WriteHeader(404)
357 w.Write([]byte(fmt.Sprintf("sub 404 %s", chkMw2)))
358 })

middleware/wrap_writer.go1

138:23exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:138:23

137
138func (b *basicWriter) Discard() {
139 b.discard = true

middleware/wrap_writer_test.go1

25:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/wrap_writer_test.go:25:6

24
25func TestHttpFancyWriterRemembersWroteHeaderWhenFlushed(t *testing.T) {
26 f := &httpFancyWriter{basicWriter: basicWriter{ResponseWriter: httptest.NewRecorder()}}

middleware/strip_test.go1

118:10add-constantstring literal "/accounts/{accountID}" appears more than twice; define a constant

middleware/strip_test.go:118:10

117
118 r.Route("/accounts/{accountID}", func(r chi.Router) {
119 r.Get("/", func(w http.ResponseWriter, r *http.Request) {

mux_test.go1

363:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:363:3

362 sr2.Get("/sub", func(w http.ResponseWriter, r *http.Request) {
363 w.Write([]byte("sub2"))
364 })

middleware/wrap_writer.go1

147:23exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:147:23

146
147func (f *flushWriter) Flush() {
148 f.wroteHeader = true

middleware/wrap_writer_test.go1

34:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/wrap_writer_test.go:34:6

33
34func TestHttp2FancyWriterRemembersWroteHeaderWhenFlushed(t *testing.T) {
35 f := &http2FancyWriter{basicWriter{ResponseWriter: httptest.NewRecorder()}}

middleware/strip_test.go1

120:33add-constantstring literal "accountID" appears more than twice; define a constant

middleware/strip_test.go:120:33

119 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
120 accountID := chi.URLParam(r, "accountID")
121 w.Write([]byte(accountID))

mux_test.go1

398:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:398:3

397 r.Get("/hi", func(w http.ResponseWriter, r *http.Request) {
398 w.Write([]byte("hi, get"))
399 })

middleware/wrap_writer.go1

160:24exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:160:24

159
160func (f *hijackWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
161 hj := f.basicWriter.ResponseWriter.(http.Hijacker)

middleware/wrap_writer_test.go1

43:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/wrap_writer_test.go:43:6

42
43func TestBasicWritesTeesWritesWithoutDiscard(t *testing.T) {
44 // explicitly create the struct instead of NewRecorder to control the value of Code

middleware/strip_test.go1

137:45add-constantstring literal "/accounts/admin" appears more than twice; define a constant

middleware/strip_test.go:137:45

136
137 if resp, body := testRequest(t, ts, "GET", "/accounts/admin", nil); body != "admin" || resp.StatusCode != 200 {
138 t.Fatal(body, resp.StatusCode)

mux_test.go1

402:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:402:3

401 r.Head("/hi", func(w http.ResponseWriter, r *http.Request) {
402 w.Write([]byte("hi, head"))
403 })

middleware/wrap_writer.go1

172:29exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:172:29

171
172func (f *flushHijackWriter) Flush() {
173 f.wroteHeader = true

middleware/wrap_writer_test.go1

63:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/wrap_writer_test.go:63:6

62
63func TestBasicWriterDiscardsWritesToOriginalResponseWriter(t *testing.T) {
64 t.Run("With Tee", func(t *testing.T) {

middleware/strip_test.go1

142:45add-constantstring literal "/accounts/admin/" appears more than twice; define a constant

middleware/strip_test.go:142:45

141 // NOTE: the testRequest client will follow the redirection..
142 if resp, body := testRequest(t, ts, "GET", "/accounts/admin/", nil); body != "admin" || resp.StatusCode != 200 {
143 t.Fatal(body, resp.StatusCode)

mux_test.go1

434:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:434:3

433 r.Get("/root", func(w http.ResponseWriter, r *http.Request) {
434 w.Write([]byte("root"))
435 })

middleware/wrap_writer.go1

178:29exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:178:29

177
178func (f *flushHijackWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
179 hj := f.basicWriter.ResponseWriter.(http.Hijacker)

middleware/wrap_writer_test.go1

64:20test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/wrap_writer_test.go:64:20

63func TestBasicWriterDiscardsWritesToOriginalResponseWriter(t *testing.T) {
64 t.Run("With Tee", func(t *testing.T) {
65 // explicitly create the struct instead of NewRecorder to control the value of Code

middleware/strip_test.go1

224:42add-constantstring literal "//" appears more than twice; define a constant

middleware/strip_test.go:224:42

223 }
224 if _, resp := testRequest(t, ts, "GET", "//", nil); resp != "root" {
225 t.Fatal(resp)

mux_test.go1

438:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:438:3

437 w.WriteHeader(405)
438 w.Write([]byte("root 405"))
439 })

middleware/wrap_writer.go1

194:27exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:194:27

193
194func (f *httpFancyWriter) Flush() {
195 f.wroteHeader = true

middleware/wrap_writer_test.go1

85:23test-parallelismconsider calling t.Parallel() when this subtest begins

middleware/wrap_writer_test.go:85:23

84
85 t.Run("Without Tee", func(t *testing.T) {
86 // explicitly create the struct instead of NewRecorder to control the value of Code

middleware/strip_test.go1

230:70add-constantstring literal "accounts" appears more than twice; define a constant

middleware/strip_test.go:230:70

229 }
230 if _, resp := testRequest(t, ts, "GET", "/accounts/", nil); resp != "accounts" {
231 t.Fatal(resp)

mux_test.go1

443:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:443:3

442 sr1.Get("/sub1", func(w http.ResponseWriter, r *http.Request) {
443 w.Write([]byte("sub1"))
444 })

middleware/wrap_writer.go1

200:27exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:200:27

199
200func (f *httpFancyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
201 hj := f.basicWriter.ResponseWriter.(http.Hijacker)

middleware/wrap_writer_test.go1

108:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/wrap_writer_test.go:108:6

107// resulting in double-counting the bytes when a Tee writer was set.
108func TestHttpFancyWriterReadFromByteCountWithTee(t *testing.T) {
109 original := &httptest.ResponseRecorder{

middleware/strip_test.go1

250:8add-constantstring literal "/accounts" appears more than twice; define a constant

middleware/strip_test.go:250:8

249
250 r.Get("/accounts", func(w http.ResponseWriter, r *http.Request) {
251 w.Write([]byte("api accounts"))

mux_test.go1

447:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:447:3

446 w.WriteHeader(405)
447 w.Write([]byte("sub1 405"))
448 })

middleware/wrap_writer.go1

205:28exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:205:28

204
205func (f *http2FancyWriter) Push(target string, opts *http.PushOptions) error {
206 return f.basicWriter.ResponseWriter.(http.Pusher).Push(target, opts)

middleware/wrap_writer_test.go1

131:6test-parallelismconsider calling t.Parallel() when this test begins

middleware/wrap_writer_test.go:131:6

130// ReaderFrom, bypassing the discard flag entirely.
131func TestHttpFancyWriterReadFromHonorsDiscard(t *testing.T) {
132 original := &readerFromRecorder{&httptest.ResponseRecorder{

middleware/strip_test.go1

263:39add-constantstring literal "api root" appears more than twice; define a constant

middleware/strip_test.go:263:39

262 if _, resp := testRequest(t, ts, "GET", "/api/", nil); resp != "api root" {
263 t.Fatalf("got: %q, want: %q", resp, "api root")
264 }

mux_test.go1

452:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:452:3

451 sr2.Get("/sub2", func(w http.ResponseWriter, r *http.Request) {
452 w.Write([]byte("sub2"))
453 })

middleware/wrap_writer.go1

209:27exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:209:27

208
209func (f *httpFancyWriter) ReadFrom(r io.Reader) (int64, error) {
210 if f.basicWriter.tee != nil || f.basicWriter.discard {

mux_test.go1

16:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:16:6

15
16func TestMuxBasic(t *testing.T) {
17 var count uint64

middleware/strip_test.go1

266:39add-constantstring literal "api accounts" appears more than twice; define a constant

middleware/strip_test.go:266:39

265 if _, resp := testRequest(t, ts, "GET", "/api/accounts", nil); resp != "api accounts" {
266 t.Fatalf("got: %q, want: %q", resp, "api accounts")
267 }

mux_test.go1

457:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:457:3

456 pathVar.Get("/{var}", func(w http.ResponseWriter, r *http.Request) {
457 w.Write([]byte("pv"))
458 })

middleware/wrap_writer.go1

239:28exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer.go:239:28

238
239func (f *http2FancyWriter) Flush() {
240 f.wroteHeader = true

mux_test.go1

208:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:208:6

207
208func TestMuxMounts(t *testing.T) {
209 r := NewRouter()

middleware/strip_test.go1

269:12add-constantstring literal "got: %q, want: %q" appears more than twice; define a constant

middleware/strip_test.go:269:12

268 if _, resp := testRequest(t, ts, "GET", "/api/accounts/admin", nil); resp != "admin" {
269 t.Fatalf("got: %q, want: %q", resp, "admin")
270 }

mux_test.go1

461:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:461:3

460 w.WriteHeader(405)
461 w.Write([]byte("pv 405"))
462 })

middleware/wrap_writer_test.go1

21:30exported-declaration-commentexported function or method should have a comment beginning with its name

middleware/wrap_writer_test.go:21:30

20
21func (r *readerFromRecorder) ReadFrom(src io.Reader) (int64, error) {
22 return io.Copy(r.ResponseRecorder.Body, src)

mux_test.go1

245:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:245:6

244
245func TestMuxPlain(t *testing.T) {
246 r := NewRouter()

middleware/strip_test.go1

306:26add-constantstring literal "Location" appears more than twice; define a constant

middleware/strip_test.go:306:26

305
306 loc := res.Header.Get("Location")
307 if loc == "" {

mux_test.go1

501:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:501:4

500 r.Get("/auth", func(w http.ResponseWriter, r *http.Request) {
501 w.Write([]byte("auth get"))
502 })

mux.go1

21:6exported-declaration-commentexported type should have a comment beginning with its name

mux.go:21:6

20// into many smaller parts composed of middlewares and end handlers.
21type Mux struct {
22 // The computed mux handler made of the chained middleware stack and

mux_test.go1

266:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:266:6

265
266func TestMuxEmptyRoutes(t *testing.T) {
267 mux := NewRouter()

middleware/sunset_test.go1

46:36add-constantstring literal "/" appears more than twice; define a constant

middleware/sunset_test.go:46:36

45 t.Run("Sunset with link", func(t *testing.T) {
46 req, _ := http.NewRequest("GET", "/", nil)
47 w := httptest.NewRecorder()

mux_test.go1

505:5discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:505:5

504 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
505 w.Write([]byte("public get"))
506 })

mux.go1

52:6exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:52:6

51// interface.
52func NewMux() *Mux {
53 mux := &Mux{tree: &node{}, pool: &sync.Pool{}}

mux_test.go1

285:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:285:6

284// for an example of using a middleware to handle trailing slashes.
285func TestMuxTrailingSlash(t *testing.T) {
286 r := NewRouter()

middleware/sunset_test.go1

71:16add-constantstring literal "Wed, 24 Dec 2025 10:20:00 GMT" appears more than twice; define a constant

middleware/sunset_test.go:71:16

70
71 if sunset != "Wed, 24 Dec 2025 10:20:00 GMT" {
72 t.Fatal("Test get sunset error.", sunset)

mux_test.go1

513:5discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:513:5

512 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
513 w.Write([]byte("private get"))
514 })

mux.go1

100:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:100:16

99// the next http.Handler.
100func (mx *Mux) Use(middlewares ...func(http.Handler) http.Handler) {
101 if mx.handler != nil {

mux_test.go1

316:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:316:6

315
316func TestMuxNestedNotFound(t *testing.T) {
317 r := NewRouter()

middleware/throttle_test.go1

95:8add-constantstring literal "/" appears more than twice; define a constant

middleware/throttle_test.go:95:8

94
95 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
96 w.WriteHeader(http.StatusOK)

mux_test.go1

522:5discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:522:5

521 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
522 w.Write([]byte("private get"))
523 })

mux.go1

109:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:109:16

108// execute the `handler` http.Handler.
109func (mx *Mux) Handle(pattern string, handler http.Handler) {
110 if i := strings.IndexAny(pattern, " \t"); i >= 0 {

mux_test.go1

394:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:394:6

393
394func TestMethodNotAllowed(t *testing.T) {
395 r := NewRouter()

middleware/url_format_test.go1

44:35add-constantstring literal "GET" appears more than twice; define a constant

middleware/url_format_test.go:44:35

43 }
44 if _, resp := testRequest(t, ts, "GET", "/samples/articles/samples.1.json", nil); resp != "1" {
45 t.Fatal(resp)

mux_test.go1

573:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:573:4

572 r.NotFound(func(w http.ResponseWriter, r *http.Request) {
573 w.Write([]byte("custom not-found"))
574 })

mux.go1

121:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:121:16

120// execute the `handlerFn` http.HandlerFunc.
121func (mx *Mux) HandleFunc(pattern string, handlerFn http.HandlerFunc) {
122 mx.Handle(pattern, handlerFn)

mux_test.go1

408:29test-parallelismconsider calling t.Parallel() when this subtest begins

mux_test.go:408:29

407
408 t.Run("Registered Method", func(t *testing.T) {
409 resp, _ := testRequest(t, ts, "GET", "/hi", nil)

middleware/url_format_test.go1

44:92add-constantstring literal "1" appears more than twice; define a constant

middleware/url_format_test.go:44:92

43 }
44 if _, resp := testRequest(t, ts, "GET", "/samples/articles/samples.1.json", nil); resp != "1" {
45 t.Fatal(resp)

mux_test.go1

583:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:583:4

582 r.NotFound(func(w http.ResponseWriter, r *http.Request) {
583 w.Write([]byte("custom not-found"))
584 })

mux.go1

127:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:127:16

126// execute the `handler` http.Handler.
127func (mx *Mux) Method(method, pattern string, handler http.Handler) {
128 m, ok := methodMap[strings.ToUpper(method)]

mux_test.go1

418:31test-parallelismconsider calling t.Parallel() when this subtest begins

mux_test.go:418:31

417
418 t.Run("Unregistered Method", func(t *testing.T) {
419 resp, _ := testRequest(t, ts, "POST", "/hi", nil)

middleware/url_format_test.go1

58:33add-constantstring literal "articleID" appears more than twice; define a constant

middleware/url_format_test.go:58:33

57 r.Get("/subroute", func(w http.ResponseWriter, r *http.Request) {
58 articleID := chi.URLParam(r, "articleID")
59 w.Write([]byte(articleID))

mux_test.go1

611:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:611:3

610 r.Get("/hi", func(w http.ResponseWriter, r *http.Request) {
611 w.Write([]byte("bye"))
612 })

mux.go1

137:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:137:16

136// execute the `handlerFn` http.HandlerFunc.
137func (mx *Mux) MethodFunc(method, pattern string, handlerFn http.HandlerFunc) {
138 mx.Method(method, pattern, handlerFn)

mux_test.go1

431:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:431:6

430
431func TestMuxNestedMethodNotAllowed(t *testing.T) {
432 r := NewRouter()

middleware/wrap_writer_test.go1

59:24add-constantstring literal "hello world" appears more than twice; define a constant

middleware/wrap_writer_test.go:59:24

58 assertEqual(t, []byte("hello world"), original.Body.Bytes())
59 assertEqual(t, []byte("hello world"), buf.Bytes())
60 assertEqual(t, 11, wrap.BytesWritten())

mux_test.go1

616:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:616:3

615 v2 := r.Context().Value(ctxKey{"inline2"}).(string)
616 w.Write([]byte(fmt.Sprintf("inline %s %s", v1, v2)))
617 })

mux.go1

143:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:143:16

142// execute the `handlerFn` http.HandlerFunc.
143func (mx *Mux) Connect(pattern string, handlerFn http.HandlerFunc) {
144 mx.handle(mCONNECT, pattern, handlerFn)

mux_test.go1

497:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:497:6

496
497func TestMuxComplicatedNotFound(t *testing.T) {
498 decorateRouter := func(r *Mux) {

mux.go1

341:33add-constantstring literal "*" appears more than twice; define a constant

mux.go:341:33

340 }
341 n := mx.handle(method, pattern+"*", mountHandler)
342

mux_test.go1

708:5discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:708:5

707 r1.Handle(tc.pattern, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
708 w.Write([]byte(tc.expectedBody))
709 }))

mux.go1

149:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:149:16

148// execute the `handlerFn` http.HandlerFunc.
149func (mx *Mux) Delete(pattern string, handlerFn http.HandlerFunc) {
150 mx.handle(mDELETE, pattern, handlerFn)

mux_test.go1

570:15test-parallelismconsider calling t.Parallel() when this subtest begins

mux_test.go:570:15

569
570 t.Run("pre", func(t *testing.T) {
571 r := NewRouter()

mux.go1

460:16add-constantstring literal "/" appears more than twice; define a constant

mux.go:460:16

459 if routePath == "" {
460 routePath = "/"
461 }

mux_test.go1

714:5discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:714:5

713 r2.HandleFunc(tc.pattern, func(w http.ResponseWriter, r *http.Request) {
714 w.Write([]byte(tc.expectedBody))
715 })

mux.go1

155:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:155:16

154// execute the `handlerFn` http.HandlerFunc.
155func (mx *Mux) Get(pattern string, handlerFn http.HandlerFunc) {
156 mx.handle(mGET, pattern, handlerFn)

mux_test.go3

579:16test-parallelismconsider calling t.Parallel() when this subtest begins

mux_test.go:579:16

578
579 t.Run("post", func(t *testing.T) {
580 r := NewRouter()
111:9add-constantstring literal "/ping" appears more than twice; define a constant

mux_test.go:111:9

110 m.Head("/ping", headPing)
111 m.Post("/ping", createPing)
112 m.Get("/ping/{id}", pingWoop)
792:5discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:792:5

791 if r.URL.Path == "/ping" {
792 w.Write([]byte("pong"))
793 return

mux.go1

161:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:161:16

160// execute the `handlerFn` http.HandlerFunc.
161func (mx *Mux) Head(pattern string, handlerFn http.HandlerFunc) {
162 mx.handle(mHEAD, pattern, handlerFn)

mux_test.go3

589:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:589:6

588
589func TestMuxWith(t *testing.T) {
590 var cmwInit1, cmwHandler1 uint64
122:35add-constantstring literal "GET" appears more than twice; define a constant

mux_test.go:122:35

121 // GET /
122 if _, body := testRequest(t, ts, "GET", "/", nil); body != "hi peter" {
123 t.Fatal(body)
805:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:805:3

804 ctxmwHandlerCount := ctx.Value(ctxKey{"count.ctxmwHandler"}).(uint64)
805 w.Write([]byte(fmt.Sprintf("inits:%d reqs:%d ctxValue:%d", ctxmwInit, handlerCount, ctxmwHandlerCount)))
806 })

mux.go1

167:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:167:16

166// execute the `handlerFn` http.HandlerFunc.
167func (mx *Mux) Options(pattern string, handlerFn http.HandlerFunc) {
168 mx.handle(mOPTIONS, pattern, handlerFn)

mux_test.go3

642:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:642:6

641
642func TestMuxHandlePatternValidation(t *testing.T) {
643 testCases := []struct {
141:69add-constantstring literal "ping all" appears more than twice; define a constant

mux_test.go:141:69

140 // GET /ping/all
141 if _, body := testRequest(t, ts, "GET", "/ping/all", nil); body != "ping all" {
142 t.Fatal(body)
809:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:809:3

808 r.Get("/hi", func(w http.ResponseWriter, r *http.Request) {
809 w.Write([]byte("wooot"))
810 })

mux.go1

173:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:173:16

172// execute the `handlerFn` http.HandlerFunc.
173func (mx *Mux) Patch(pattern string, handlerFn http.HandlerFunc) {
174 mx.handle(mPATCH, pattern, handlerFn)

mux_test.go3

699:18test-parallelismconsider calling t.Parallel() when this subtest begins

mux_test.go:699:18

698 for _, tc := range testCases {
699 t.Run(tc.name, func(t *testing.T) {
700 defer func() {
198:21add-constantstring literal "catchall" appears more than twice; define a constant

mux_test.go:198:21

197
198 if string(body) != "catchall" {
199 t.Error("expecting response body: 'catchall'")
853:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:853:4

852 r.Get("/group", func(w http.ResponseWriter, r *http.Request) {
853 w.Write([]byte("root group"))
854 })

mux.go1

179:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:179:16

178// execute the `handlerFn` http.HandlerFunc.
179func (mx *Mux) Post(pattern string, handlerFn http.HandlerFunc) {
180 mx.handle(mPOST, pattern, handlerFn)

mux_test.go3

754:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:754:6

753
754func TestMuxMiddlewareStack(t *testing.T) {
755 var stdmwInit, stdmwHandler uint64
217:9add-constantstring literal "/" appears more than twice; define a constant

mux_test.go:217:9

216 r.Route("/{hash}/share", func(r Router) {
217 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
218 v := URLParam(r, "hash")
859:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:859:4

858 r.Get("/group2", func(w http.ResponseWriter, r *http.Request) {
859 w.Write([]byte("root group2"))
860 })

mux.go1

185:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:185:16

184// execute the `handlerFn` http.HandlerFunc.
185func (mx *Mux) Put(pattern string, handlerFn http.HandlerFunc) {
186 mx.handle(mPUT, pattern, handlerFn)

mux_test.go3

829:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:829:6

828
829func TestMuxRouteGroups(t *testing.T) {
830 var stdmwInit, stdmwHandler uint64
222:21add-constantstring literal "hash" appears more than twice; define a constant

mux_test.go:222:21

221 r.Get("/{network}", func(w http.ResponseWriter, r *http.Request) {
222 v := URLParam(r, "hash")
223 n := URLParam(r, "network")
980:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:980:4

979 r.Get("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
980 w.Write([]byte("fav"))
981 })

mux.go1

191:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:191:16

190// execute the `handlerFn` http.HandlerFunc.
191func (mx *Mux) Query(pattern string, handlerFn http.HandlerFunc) {
192 mx.handle(mQUERY, pattern, handlerFn)

mux_test.go3

885:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:885:6

884
885func TestMuxBig(t *testing.T) {
886 r := bigMux()
289:18add-constantstring literal "nothing here" appears more than twice; define a constant

mux_test.go:289:18

288 w.WriteHeader(404)
289 w.Write([]byte("nothing here"))
290 })
986:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:986:4

985 ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
986 w.Write([]byte(s))
987 })

mux.go1

197:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:197:16

196// execute the `handlerFn` http.HandlerFunc.
197func (mx *Mux) Trace(pattern string, handlerFn http.HandlerFunc) {
198 mx.handle(mTRACE, pattern, handlerFn)

mux_test.go3

1096:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1096:6

1095
1096func TestMuxSubroutesBasic(t *testing.T) {
1097 hIndex := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
326:8add-constantstring literal "/hi" appears more than twice; define a constant

mux_test.go:326:8

325
326 r.Get("/hi", func(w http.ResponseWriter, r *http.Request) {
327 w.Write([]byte("bye"))
992:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:992:4

991 URLParam(r, "*"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
992 w.Write([]byte(s))
993 })

mux.go1

203:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:203:16

202// not be found. The default 404 handler is `http.NotFound`.
203func (mx *Mux) NotFound(handlerFn http.HandlerFunc) {
204 // Build NotFound handler chain

mux_test.go3

1177:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1177:6

1176
1177func TestMuxSubroutes(t *testing.T) {
1178 hHubView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
327:18add-constantstring literal "bye" appears more than twice; define a constant

mux_test.go:327:18

326 r.Get("/hi", func(w http.ResponseWriter, r *http.Request) {
327 w.Write([]byte("bye"))
328 })
998:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:998:4

997 URLParam(r, "*"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
998 w.Write([]byte(s))
999 })

mux.go1

223:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:223:16

222// method is unresolved. The default handler returns a 405 with an empty body.
223func (mx *Mux) MethodNotAllowed(handlerFn http.HandlerFunc) {
224 // Build MethodNotAllowed handler chain

mux_test.go3

1292:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1292:6

1291
1292func TestSingleHandler(t *testing.T) {
1293 h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
336:37add-constantstring literal "mw" appears more than twice; define a constant

mux_test.go:336:37

335 }).NotFound(func(w http.ResponseWriter, r *http.Request) {
336 chkMw := r.Context().Value(ctxKey{"mw"}).(string)
337 chkWith := r.Context().Value(ctxKey{"with"}).(string)
1011:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1011:4

1010 s := fmt.Sprintf("/ reqid:%s session:%s", ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
1011 w.Write([]byte(s))
1012 })

mux.go1

268:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:268:16

267// set of middlewares. See _examples/.
268func (mx *Mux) Group(fn func(r Router)) Router {
269 im := mx.With()

mux_test.go3

1336:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1336:6

1335
1336func TestServeHTTPExistingContext(t *testing.T) {
1337 r := NewRouter()
337:39add-constantstring literal "with" appears more than twice; define a constant

mux_test.go:337:39

336 chkMw := r.Context().Value(ctxKey{"mw"}).(string)
337 chkWith := r.Context().Value(ctxKey{"with"}).(string)
338 w.WriteHeader(404)
1016:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1016:4

1015 s := fmt.Sprintf("/suggestions reqid:%s session:%s", ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
1016 w.Write([]byte(s))
1017 })

mux.go1

278:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:278:16

277// Effectively, this is a short-hand call to Mount. See _examples/.
278func (mx *Mux) Route(pattern string, fn func(r Router)) Router {
279 if fn == nil {

mux_test.go3

1392:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1392:6

1391
1392func TestNestedGroups(t *testing.T) {
1393 handlerPrintCounter := func(w http.ResponseWriter, r *http.Request) {
355:39add-constantstring literal "mw2" appears more than twice; define a constant

mux_test.go:355:39

354 sr1.NotFound(func(w http.ResponseWriter, r *http.Request) {
355 chkMw2 := r.Context().Value(ctxKey{"mw2"}).(string)
356 w.WriteHeader(404)
1021:4discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1021:4

1020 s := fmt.Sprintf("/woot/%s/%s", URLParam(r, "wootID"), URLParam(r, "*"))
1021 w.Write([]byte(s))
1022 })

mux.go1

295:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:295:16

294// if you define two Mount() routes on the exact same pattern the mount will panic.
295func (mx *Mux) Mount(pattern string, handler http.Handler) {
296 if handler == nil {

mux_test.go3

1448:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1448:6

1447
1448func TestMiddlewarePanicOnLateUse(t *testing.T) {
1449 handler := func(w http.ResponseWriter, r *http.Request) {
375:42add-constantstring literal "/nothing-here" appears more than twice; define a constant

mux_test.go:375:42

374 }
375 if _, body := testRequest(t, ts, "GET", "/nothing-here", nil); body != "root 404 mw with" {
376 t.Fatal(body)
1032:6discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1032:6

1031 URLParam(r, "hubID"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
1032 w.Write([]byte(s))
1033 })

mux.go1

350:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:350:16

349// useful for traversing available routes of a router.
350func (mx *Mux) Routes() []Route {
351 return mx.tree.routes()

mux_test.go3

1470:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1470:6

1469
1470func TestMountingExistingPath(t *testing.T) {
1471 handler := func(w http.ResponseWriter, r *http.Request) {}
452:18add-constantstring literal "sub2" appears more than twice; define a constant

mux_test.go:452:18

451 sr2.Get("/sub2", func(w http.ResponseWriter, r *http.Request) {
452 w.Write([]byte("sub2"))
453 })
1038:6discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1038:6

1037 ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
1038 w.Write([]byte(s))
1039 })

mux.go1

365:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:365:16

364// the state carefully or make a NewRouteContext().
365func (mx *Mux) Match(rctx *Context, method, path string) bool {
366 return mx.Find(rctx, method, path) != ""

mux_test.go3

1485:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1485:6

1484
1485func TestMountingSimilarPattern(t *testing.T) {
1486 r := NewRouter()
474:42add-constantstring literal "/root" appears more than twice; define a constant

mux_test.go:474:42

473 }
474 if _, body := testRequest(t, ts, "PUT", "/root", nil); body != "root 405" {
475 t.Fatal(body)
1046:6discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1046:6

1045 ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
1046 w.Write([]byte(s))
1047 })

mux.go1

374:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:374:16

373// the state carefully or make a NewRouteContext().
374func (mx *Mux) Find(rctx *Context, method, path string) string {
375 m, ok := methodMap[method]

mux_test.go3

1512:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1512:6

1511
1512func TestMuxEmptyParams(t *testing.T) {
1513 r := NewRouter()
486:35add-constantstring literal "PUT" appears more than twice; define a constant

mux_test.go:486:35

485 }
486 if _, body := testRequest(t, ts, "PUT", "/prefix2/sub2", nil); body != "root 405" {
487 t.Fatal(body)
1054:7discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1054:7

1053 URLParam(r, "webhookID"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
1054 w.Write([]byte(s))
1055 })

mux.go1

404:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:404:16

403// cannot be found.
404func (mx *Mux) NotFoundHandler() http.HandlerFunc {
405 if mx.notFoundHandler != nil {

mux_test.go3

1532:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1532:6

1531
1532func TestMuxMissingParams(t *testing.T) {
1533 r := NewRouter()
486:73add-constantstring literal "root 405" appears more than twice; define a constant

mux_test.go:486:73

485 }
486 if _, body := testRequest(t, ts, "PUT", "/prefix2/sub2", nil); body != "root 405" {
487 t.Fatal(body)
1070:7discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1070:7

1069 ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
1070 w.Write([]byte(s))
1071 })

mux.go1

413:16exported-declaration-commentexported function or method should have a comment beginning with its name

mux.go:413:16

412// a method cannot be resolved for a route.
413func (mx *Mux) MethodNotAllowedHandler(methodsAllowed ...methodTyp) http.HandlerFunc {
414 if mx.methodNotAllowedHandler != nil {

mux_test.go3

1554:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1554:6

1553
1554func TestMuxWildcardRoute(t *testing.T) {
1555 handler := func(w http.ResponseWriter, r *http.Request) {}
539:69add-constantstring literal "public get" appears more than twice; define a constant

mux_test.go:539:69

538 }
539 if _, body := testRequest(t, ts, "GET", "/public/", nil); body != "public get" {
540 t.Fatal(body)
1082:5discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1082:5

1081 ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
1082 w.Write([]byte(s))
1083 })

tree.go1

69:6exported-declaration-commentexported function or method should have a comment beginning with its name

tree.go:69:6

68// via Router#Method and Router#MethodFunc
69func RegisterMethod(method string) {
70 if method == "" {

mux_test.go3

1567:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1567:6

1566
1567func TestMuxWildcardRouteCheckTwo(t *testing.T) {
1568 handler := func(w http.ResponseWriter, r *http.Request) {}
542:78add-constantstring literal "private get" appears more than twice; define a constant

mux_test.go:542:78

541 }
542 if _, body := testRequest(t, ts, "GET", "/private/resource", nil); body != "private get" {
543 t.Fatal(body)
1088:5discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1088:5

1087 ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
1088 w.Write([]byte(s))
1089 })

tree.go1

138:20exported-declaration-commentexported function or method should have a comment beginning with its name

tree.go:138:20

137
138func (s endpoints) Value(method methodTyp) *endpoint {
139 mh, ok := s[method]

mux_test.go3

1580:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1580:6

1579
1580func TestMuxRegexp(t *testing.T) {
1581 r := NewRouter()
552:74add-constantstring literal "custom not-found" appears more than twice; define a constant

mux_test.go:552:74

551 }
552 if _, body := testRequest(t, ts, "GET", "/private/nope", nil); body != "custom not-found" {
553 t.Fatal(body)
1098:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1098:3

1097 hIndex := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1098 w.Write([]byte("index"))
1099 })

tree.go1

147:16exported-declaration-commentexported function or method should have a comment beginning with its name

tree.go:147:16

146
147func (n *node) InsertRoute(method methodTyp, pattern string, handler http.Handler) *node {
148 var parent *node

mux_test.go3

1596:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1596:6

1595
1596func TestMuxRegexp2(t *testing.T) {
1597 r := NewRouter()
869:12add-constantstring literal "got: '%s'" appears more than twice; define a constant

mux_test.go:869:12

868 if body != "root group" {
869 t.Fatalf("got: '%s'", body)
870 }
1101:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1101:3

1100 hArticlesList := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1101 w.Write([]byte("articles-list"))
1102 })

tree.go1

382:16exported-declaration-commentexported function or method should have a comment beginning with its name

tree.go:382:16

381
382func (n *node) FindRoute(rctx *Context, method methodTyp, path string) (*node, endpoints, http.Handler) {
383 // Reset the context routing pattern and params

mux_test.go3

1612:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1612:6

1611
1612func TestMuxRegexp3(t *testing.T) {
1613 r := NewRouter()
905:31add-constantstring literal "POST" appears more than twice; define a constant

mux_test.go:905:31

904 }
905 _, body = testRequest(t, ts, "POST", "/hubs/ethereumhub/view/index.html", nil)
906 if body != "/hubs/ethereumhub/view/index.html reqid:1 session:anonymous" {
1104:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1104:3

1103 hSearchArticles := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1104 w.Write([]byte("search-articles"))
1105 })

tree.go1

795:17exported-declaration-commentexported function or method should have a comment beginning with its name

tree.go:795:17

794func (ns nodes) Sort() { sort.Sort(ns); ns.tailSort() }
795func (ns nodes) Len() int { return len(ns) }
796func (ns nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }

mux_test.go3

1653:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1653:6

1652
1653func TestMuxSubrouterWildcardParam(t *testing.T) {
1654 h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
907:12add-constantstring literal "got '%s'" appears more than twice; define a constant

mux_test.go:907:12

906 if body != "/hubs/ethereumhub/view/index.html reqid:1 session:anonymous" {
907 t.Fatalf("got '%s'", body)
908 }
1107:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1107:3

1106 hGetArticle := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1107 w.Write([]byte(fmt.Sprintf("get-article:%s", URLParam(r, "id"))))
1108 })

tree.go1

796:17exported-declaration-commentexported function or method should have a comment beginning with its name

tree.go:796:17

795func (ns nodes) Len() int { return len(ns) }
796func (ns nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }
797func (ns nodes) Less(i, j int) bool { return ns[i].label < ns[j].label }

mux_test.go3

1685:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1685:6

1684
1685func TestMuxContextIsThreadSafe(t *testing.T) {
1686 router := NewRouter()
939:13add-constantstring literal "404 page not found\n" appears more than twice; define a constant

mux_test.go:939:13

938 _, body = testRequest(t, ts, "GET", "/folders", nil)
939 if body != "404 page not found\n" {
940 t.Fatalf("got '%s'", body)
1110:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1110:3

1109 hSyncArticle := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1110 w.Write([]byte(fmt.Sprintf("sync-article:%s", URLParam(r, "id"))))
1111 })

tree.go1

797:17exported-declaration-commentexported function or method should have a comment beginning with its name

tree.go:797:17

796func (ns nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }
797func (ns nodes) Less(i, j int) bool { return ns[i].label < ns[j].label }
798

mux_test.go3

1721:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1721:6

1720
1721func TestEscapedURLParams(t *testing.T) {
1722 m := NewRouter()
991:40add-constantstring literal "requestID" appears more than twice; define a constant

mux_test.go:991:40

990 s := fmt.Sprintf("/hubs/%s/view/%s reqid:%s session:%s", URLParamFromCtx(ctx, "hubID"),
991 URLParam(r, "*"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
992 w.Write([]byte(s))
1179:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1179:3

1178 hHubView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1179 w.Write([]byte("hub1"))
1180 })

tree.go1

832:6exported-declaration-commentexported type should have a comment beginning with its name

tree.go:832:6

831// Handlers map key is an HTTP method
832type Route struct {
833 SubRoutes Routes

mux_test.go11

1761:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1761:6

1760
1761func TestCustomHTTPMethod(t *testing.T) {
1762 // first we must register this method to be accepted, then we
991:72add-constantstring literal "session.user" appears more than twice; define a constant

mux_test.go:991:72

990 s := fmt.Sprintf("/hubs/%s/view/%s reqid:%s session:%s", URLParamFromCtx(ctx, "hubID"),
991 URLParam(r, "*"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
992 w.Write([]byte(s))
1182:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1182:3

1181 hHubView2 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1182 w.Write([]byte("hub2"))
1183 })
1807:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1807:6

1806
1807func TestQueryHTTPMethod(t *testing.T) {
1808 r := NewRouter()
1020:71add-constantstring literal "*" appears more than twice; define a constant

mux_test.go:1020:71

1019 r.Get("/woot/{wootID}/*", func(w http.ResponseWriter, r *http.Request) {
1020 s := fmt.Sprintf("/woot/%s/%s", URLParam(r, "wootID"), URLParam(r, "*"))
1021 w.Write([]byte(s))
1185:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1185:3

1184 hHubView3 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1185 w.Write([]byte("hub3"))
1186 })
1858:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1858:6

1857
1858func TestMuxMatch(t *testing.T) {
1859 r := NewRouter()
1031:19add-constantstring literal "hubID" appears more than twice; define a constant

mux_test.go:1031:19

1030 s := fmt.Sprintf("/hubs/%s reqid:%s session:%s",
1031 URLParam(r, "hubID"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"}))
1032 w.Write([]byte(s))
1188:3discarded-error-resulterror result returned by w.Write is discarded

mux_test.go:1188:3

1187 hAccountView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1188 w.Write([]byte("account1"))
1189 })
1896:6test-parallelismconsider calling t.Parallel() when this test begins

mux_test.go:1896:6

1895
1896func TestMuxMatch_HasBasePath(t *testing.T) {
1897 r := NewRouter()
1084:10add-constantstring literal "/public" appears more than twice; define a constant

mux_test.go:1084:10

1083 })
1084 r.Get("/public", func(w http.ResponseWriter, r *http.Request) {
1085 ctx := r.Context()