Skip to content

Commit 5df0663

Browse files
committed
Formatting
1 parent e5cc9ee commit 5df0663

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

bear-tests_test.go

+38-4
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ func TestBadHandler(t *testing.T) {
190190
t.Errorf("handlerBad should not be accepted")
191191
}
192192
}
193+
193194
func TestBadVerbOn(t *testing.T) {
194195
mux := New()
195196
verb := "BLUB"
@@ -198,6 +199,7 @@ func TestBadVerbOn(t *testing.T) {
198199
t.Errorf("%s should not be accepted", verb)
199200
}
200201
}
202+
201203
func TestBadVerbServe(t *testing.T) {
202204
var (
203205
method = "BLUB"
@@ -217,6 +219,7 @@ func TestBadVerbServe(t *testing.T) {
217219
t.Errorf("%s %s got %d want %d", method, path, res.Code, want)
218220
}
219221
}
222+
220223
func TestDuplicateFailure(t *testing.T) {
221224
var (
222225
handler HandlerFunc
@@ -235,6 +238,7 @@ func TestDuplicateFailure(t *testing.T) {
235238
}
236239
}
237240
}
241+
238242
func TestDuplicateFailureRoot(t *testing.T) {
239243
var (
240244
handler HandlerFunc
@@ -253,6 +257,7 @@ func TestDuplicateFailureRoot(t *testing.T) {
253257
}
254258
}
255259
}
260+
256261
func TestMiddleware(t *testing.T) {
257262
var (
258263
middlewares int = 4
@@ -328,6 +333,7 @@ func TestMiddleware(t *testing.T) {
328333
run(verb)
329334
}
330335
}
336+
331337
func TestMiddlewareRejectionA(t *testing.T) {
332338
mux := New()
333339
one := func(http.ResponseWriter, *http.Request, *Context) {}
@@ -337,6 +343,7 @@ func TestMiddlewareRejectionA(t *testing.T) {
337343
t.Errorf("middleware with wrong signature was accepted")
338344
}
339345
}
346+
340347
func TestMiddlewareRejectionB(t *testing.T) {
341348
mux := New()
342349
one := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
@@ -348,6 +355,7 @@ func TestMiddlewareRejectionB(t *testing.T) {
348355
t.Errorf("middleware with wrong signature was accepted")
349356
}
350357
}
358+
351359
func TestMiddlewareRejectionC(t *testing.T) {
352360
mux := New()
353361
one := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
@@ -356,6 +364,7 @@ func TestMiddlewareRejectionC(t *testing.T) {
356364
t.Errorf("middleware with wrong signature was accepted")
357365
}
358366
}
367+
359368
func TestMiddlewareRejectionD(t *testing.T) {
360369
mux := New()
361370
one := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
@@ -364,6 +373,7 @@ func TestMiddlewareRejectionD(t *testing.T) {
364373
t.Errorf("middleware with wrong signature was accepted")
365374
}
366375
}
376+
367377
func TestMiddlewareRejectionE(t *testing.T) {
368378
mux := New()
369379
var (
@@ -389,6 +399,7 @@ func TestMiddlewareRejectionE(t *testing.T) {
389399
t.Errorf("nil middleware was accepted")
390400
}
391401
}
402+
392403
func TestNoHandlers(t *testing.T) {
393404
var (
394405
mux *Mux = New()
@@ -406,6 +417,7 @@ func TestNoHandlers(t *testing.T) {
406417
}
407418
}
408419
}
420+
409421
func TestNotFoundCustom(t *testing.T) {
410422
var (
411423
method string = "GET"
@@ -448,6 +460,7 @@ func TestNotFoundCustom(t *testing.T) {
448460
method, pathLost, patternLost, res.Code, wantLost)
449461
}
450462
}
463+
451464
func TestNotFoundNoParams(t *testing.T) {
452465
var (
453466
path = "/foo/bar"
@@ -472,6 +485,7 @@ func TestNotFoundNoParams(t *testing.T) {
472485
verb, path, pattern, want)(t)
473486
}
474487
}
488+
475489
func TestNotFoundParams(t *testing.T) {
476490
var (
477491
path = "/foo/BAR/baz"
@@ -496,6 +510,7 @@ func TestNotFoundParams(t *testing.T) {
496510
verb, path, pattern, want)(t)
497511
}
498512
}
513+
499514
func TestNotFoundRoot(t *testing.T) {
500515
var (
501516
method string = "GET"
@@ -512,6 +527,7 @@ func TestNotFoundRoot(t *testing.T) {
512527
t.Errorf("%s %s got %d want %d", method, path, res.Code, want)
513528
}
514529
}
530+
515531
func TestNotFoundWildA(t *testing.T) {
516532
var (
517533
path = "/foo"
@@ -536,6 +552,7 @@ func TestNotFoundWildA(t *testing.T) {
536552
verb, path, pattern, want)(t)
537553
}
538554
}
555+
539556
func TestNotFoundWildB(t *testing.T) {
540557
var (
541558
method string = "GET"
@@ -557,6 +574,7 @@ func TestNotFoundWildB(t *testing.T) {
557574
t.Errorf("%s %s got %d want %d", method, path, res.Code, want)
558575
}
559576
}
577+
560578
func TestOKMultiRuleParams(t *testing.T) {
561579
var (
562580
method string = "GET"
@@ -578,6 +596,7 @@ func TestOKMultiRuleParams(t *testing.T) {
578596
t.Errorf("%s %s got %d want %d", method, path, res.Code, want)
579597
}
580598
}
599+
581600
func TestOKNoParams(t *testing.T) {
582601
var (
583602
path = "/foo/bar"
@@ -599,6 +618,7 @@ func TestOKNoParams(t *testing.T) {
599618
verb, path, pattern, want)(t)
600619
}
601620
}
621+
602622
func TestOKParams(t *testing.T) {
603623
var (
604624
path = "/foo/BAR/baz/QUX"
@@ -621,6 +641,7 @@ func TestOKParams(t *testing.T) {
621641
verb, path, pattern, want)(t)
622642
}
623643
}
644+
624645
func TestOKParamsTrailingSlash(t *testing.T) {
625646
var (
626647
path = "/foo/BAR/baz/QUX/"
@@ -643,6 +664,7 @@ func TestOKParamsTrailingSlash(t *testing.T) {
643664
verb, path, pattern, want)(t)
644665
}
645666
}
667+
646668
func TestOKRoot(t *testing.T) {
647669
var (
648670
path = "/"
@@ -664,6 +686,7 @@ func TestOKRoot(t *testing.T) {
664686
verb, path, pattern, want)(t)
665687
}
666688
}
689+
667690
func TestOKWildRoot(t *testing.T) {
668691
var (
669692
path = "/"
@@ -685,6 +708,7 @@ func TestOKWildRoot(t *testing.T) {
685708
verb, path, pattern, want)(t)
686709
}
687710
}
711+
688712
func TestSanitizePatternPrefixSuffix(t *testing.T) {
689713
var (
690714
method = "GET"
@@ -707,6 +731,7 @@ func TestSanitizePatternPrefixSuffix(t *testing.T) {
707731
t.Errorf("%s %s (%s) got %s want %s", method, path, pattern, body, want)
708732
}
709733
}
734+
710735
func TestSanitizePatternDoubleSlash(t *testing.T) {
711736
var (
712737
method = "GET"
@@ -729,6 +754,7 @@ func TestSanitizePatternDoubleSlash(t *testing.T) {
729754
t.Errorf("%s %s (%s) got %s want %s", method, path, pattern, body, want)
730755
}
731756
}
757+
732758
func TestUnreachableA(t *testing.T) {
733759
mux := New()
734760
one := func(http.ResponseWriter, *http.Request, *Context) {}
@@ -739,6 +765,7 @@ func TestUnreachableA(t *testing.T) {
739765
t.Errorf("unreachable A")
740766
}
741767
}
768+
742769
func TestUnreachableB(t *testing.T) {
743770
mux := New()
744771
one := func(http.ResponseWriter, *http.Request, *Context) {}
@@ -749,6 +776,7 @@ func TestUnreachableB(t *testing.T) {
749776
t.Errorf("unreachable B")
750777
}
751778
}
779+
752780
func TestWildcardCompeting(t *testing.T) {
753781
var (
754782
method string = "GET"
@@ -797,6 +825,7 @@ func TestWildcardCompeting(t *testing.T) {
797825
method, pathThree, patternThree, body, wantThree)
798826
}
799827
}
828+
800829
func TestWildcardMethod(t *testing.T) {
801830
var (
802831
mux = New()
@@ -821,6 +850,7 @@ func TestWildcardMethod(t *testing.T) {
821850
}
822851
}
823852
}
853+
824854
func TestWildcardMethodWarning(t *testing.T) {
825855
var (
826856
mux = New()
@@ -835,6 +865,7 @@ func TestWildcardMethodWarning(t *testing.T) {
835865
t.Errorf("* %s should have registered, but with an error", pattern)
836866
}
837867
}
868+
838869
func TestWildcardNotLast(t *testing.T) {
839870
var (
840871
mux = New()
@@ -848,6 +879,7 @@ func TestWildcardNotLast(t *testing.T) {
848879
pattern)
849880
}
850881
}
882+
851883
func TestWildcardParams(t *testing.T) {
852884
var (
853885
method = "GET"
@@ -870,6 +902,7 @@ func TestWildcardParams(t *testing.T) {
870902
t.Errorf("%s %s (%s) got %s want %s", method, path, pattern, body, want)
871903
}
872904
}
905+
873906
func TestAlways(t *testing.T) {
874907
var (
875908
mux *Mux = New()
@@ -934,6 +967,7 @@ func TestAlwaysBeforeNotFound(t *testing.T) {
934967
res = httptest.NewRecorder()
935968
mux.ServeHTTP(res, req)
936969
}
970+
937971
func TestAlwaysRejection(t *testing.T) {
938972
var (
939973
mux *Mux = New()
@@ -943,15 +977,15 @@ func TestAlwaysRejection(t *testing.T) {
943977
four func(http.ResponseWriter, *http.Request, *Context)
944978
)
945979
if err := mux.Always(one); err == nil {
946-
t.Errorf("Always requires non-nil HandlerFunc or its signature")
980+
t.Errorf("Always requires non-nil handler")
947981
}
948982
if err := mux.Always(two); err == nil {
949-
t.Errorf("Always requires non-nil HandlerFunc or its signature")
983+
t.Errorf("Always requires non-nil handler")
950984
}
951985
if err := mux.Always(three); err == nil {
952-
t.Errorf("Always requires non-nil HandlerFunc or its signature")
986+
t.Errorf("Always requires non-nil handler")
953987
}
954988
if err := mux.Always(four); err == nil {
955-
t.Errorf("Always requires non-nil HandlerFunc or its signature")
989+
t.Errorf("Always requires non-nil handler")
956990
}
957991
}

bear.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,13 @@ var (
2222
dyn = regexp.MustCompile(`\{(\w+)\}`)
2323
dbl = regexp.MustCompile(`[\/]{2,}`)
2424
verbs = [8]string{
25-
"CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT", "TRACE"}
25+
"CONNECT",
26+
"DELETE",
27+
"GET",
28+
"HEAD",
29+
"OPTIONS",
30+
"POST",
31+
"PUT",
32+
"TRACE",
33+
}
2634
)

handlerfunc.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ func handlerizeLax(
8282
unreachable := false
8383
for _, function := range functions {
8484
if unreachable {
85-
err := fmt.Errorf(
86-
"bear: %s %s has unreachable middleware",
87-
verb, pattern)
85+
err := fmt.Errorf("bear: %s %s has unreachable middleware", verb, pattern)
8886
return nil, err
8987
}
9088
if handler, followable, err := handlerize(function); err != nil {
@@ -99,7 +97,8 @@ func handlerizeLax(
9997
return handlers, nil
10098
}
10199

102-
func handlerizeStrict(functions []interface{}) (handlers []HandlerFunc, err error) {
100+
func handlerizeStrict(functions []interface{}) ([]HandlerFunc, error) {
101+
var handlers []HandlerFunc
103102
for _, function := range functions {
104103
switch function.(type) {
105104
case HandlerFunc:

mux.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,8 @@ func (mux *Mux) tree(name string) (*tree, *bool) {
249249
// New returns a pointer to a Mux instance
250250
func New() *Mux {
251251
mux := new(Mux)
252-
mux.trees = [8]*tree{
253-
{}, {}, {}, {},
254-
{}, {}, {}, {}}
255-
mux.wild = [8]bool{
256-
false, false, false, false,
257-
false, false, false, false}
252+
mux.trees = [8]*tree{{}, {}, {}, {}, {}, {}, {}, {}}
253+
mux.wild = [8]bool{false, false, false, false, false, false, false, false}
258254
return mux
259255

260256
}

0 commit comments

Comments
 (0)