Skip to content

Commit cd09769

Browse files
committed
feat(router): akumu router
1 parent 9a78f7b commit cd09769

11 files changed

+479
-22
lines changed

akumu.test

5.79 MB
Binary file not shown.

cover.out

+233
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
mode: set
2+
github.com/studiolambda/akumu/middleware/logger.go:11.51,12.49 1 0
3+
github.com/studiolambda/akumu/middleware/logger.go:12.49,14.3 1 0
4+
github.com/studiolambda/akumu/middleware/logger.go:17.39,18.49 1 0
5+
github.com/studiolambda/akumu/middleware/logger.go:18.49,20.3 1 0
6+
github.com/studiolambda/akumu/middleware/logger.go:23.73,24.82 1 0
7+
github.com/studiolambda/akumu/middleware/logger.go:24.82,28.89 2 0
8+
github.com/studiolambda/akumu/middleware/logger.go:28.89,29.35 1 0
9+
github.com/studiolambda/akumu/middleware/logger.go:29.35,31.6 1 0
10+
github.com/studiolambda/akumu/middleware/logger.go:33.5,40.6 1 0
11+
github.com/studiolambda/akumu/middleware/problems.go:10.64,11.49 1 0
12+
github.com/studiolambda/akumu/middleware/problems.go:11.49,12.83 1 0
13+
github.com/studiolambda/akumu/middleware/problems.go:12.83,16.4 1 0
14+
github.com/studiolambda/akumu/middleware/recover.go:15.33,16.49 1 0
15+
github.com/studiolambda/akumu/middleware/recover.go:16.49,17.53 1 0
16+
github.com/studiolambda/akumu/middleware/recover.go:17.53,18.33 1 0
17+
github.com/studiolambda/akumu/middleware/recover.go:19.15,20.15 1 0
18+
github.com/studiolambda/akumu/middleware/recover.go:21.16,22.27 1 0
19+
github.com/studiolambda/akumu/middleware/recover.go:23.22,24.36 1 0
20+
github.com/studiolambda/akumu/middleware/recover.go:27.4,27.24 1 0
21+
github.com/studiolambda/akumu/middleware/recover.go:32.83,33.82 1 0
22+
github.com/studiolambda/akumu/middleware/recover.go:33.82,34.16 1 0
23+
github.com/studiolambda/akumu/middleware/recover.go:34.16,35.36 1 0
24+
github.com/studiolambda/akumu/middleware/recover.go:35.36,39.5 1 0
25+
github.com/studiolambda/akumu/middleware/recover.go:42.3,42.37 1 0
26+
github.com/studiolambda/akumu/builder.go:27.69,28.43 1 1
27+
github.com/studiolambda/akumu/builder.go:28.43,29.32 1 1
28+
github.com/studiolambda/akumu/builder.go:29.32,31.4 1 1
29+
github.com/studiolambda/akumu/builder.go:34.2,36.54 2 1
30+
github.com/studiolambda/akumu/builder.go:39.98,42.24 2 1
31+
github.com/studiolambda/akumu/builder.go:42.24,47.3 3 1
32+
github.com/studiolambda/akumu/builder.go:49.2,49.27 1 1
33+
github.com/studiolambda/akumu/builder.go:49.27,50.36 1 0
34+
github.com/studiolambda/akumu/builder.go:50.36,51.18 1 0
35+
github.com/studiolambda/akumu/builder.go:51.18,58.5 1 0
36+
github.com/studiolambda/akumu/builder.go:61.3,62.9 2 0
37+
github.com/studiolambda/akumu/builder.go:65.2,65.25 1 1
38+
github.com/studiolambda/akumu/builder.go:65.25,68.17 2 1
39+
github.com/studiolambda/akumu/builder.go:68.17,74.4 2 0
40+
github.com/studiolambda/akumu/builder.go:76.3,76.36 1 1
41+
github.com/studiolambda/akumu/builder.go:76.36,77.18 1 1
42+
github.com/studiolambda/akumu/builder.go:77.18,85.5 1 0
43+
github.com/studiolambda/akumu/builder.go:88.3,90.9 2 1
44+
github.com/studiolambda/akumu/builder.go:93.2,93.27 1 1
45+
github.com/studiolambda/akumu/builder.go:93.27,96.10 2 0
46+
github.com/studiolambda/akumu/builder.go:96.10,102.4 2 0
47+
github.com/studiolambda/akumu/builder.go:104.3,104.36 1 0
48+
github.com/studiolambda/akumu/builder.go:104.36,105.18 1 0
49+
github.com/studiolambda/akumu/builder.go:105.18,112.5 1 0
50+
github.com/studiolambda/akumu/builder.go:115.3,117.7 2 0
51+
github.com/studiolambda/akumu/builder.go:117.7,118.11 1 0
52+
github.com/studiolambda/akumu/builder.go:119.36,120.11 1 0
53+
github.com/studiolambda/akumu/builder.go:121.41,122.12 1 0
54+
github.com/studiolambda/akumu/builder.go:122.12,124.6 1 0
55+
github.com/studiolambda/akumu/builder.go:126.5,128.20 2 0
56+
github.com/studiolambda/akumu/builder.go:133.2,133.35 1 1
57+
github.com/studiolambda/akumu/builder.go:133.35,134.17 1 0
58+
github.com/studiolambda/akumu/builder.go:134.17,141.4 1 0
59+
github.com/studiolambda/akumu/builder.go:145.35,153.2 1 1
60+
github.com/studiolambda/akumu/builder.go:155.32,158.2 1 1
61+
github.com/studiolambda/akumu/builder.go:160.39,162.2 1 0
62+
github.com/studiolambda/akumu/builder.go:164.51,168.2 2 0
63+
github.com/studiolambda/akumu/builder.go:170.61,174.2 2 0
64+
github.com/studiolambda/akumu/builder.go:176.58,181.2 3 1
65+
github.com/studiolambda/akumu/builder.go:183.64,188.2 3 0
66+
github.com/studiolambda/akumu/builder.go:190.50,192.2 1 1
67+
github.com/studiolambda/akumu/builder.go:194.59,198.2 2 1
68+
github.com/studiolambda/akumu/builder.go:200.61,206.2 2 0
69+
github.com/studiolambda/akumu/builder.go:208.58,212.2 1 0
70+
github.com/studiolambda/akumu/builder.go:214.59,215.35 1 0
71+
github.com/studiolambda/akumu/builder.go:215.35,217.3 1 0
72+
github.com/studiolambda/akumu/builder.go:219.2,219.16 1 0
73+
github.com/studiolambda/akumu/builder.go:222.50,226.2 2 1
74+
github.com/studiolambda/akumu/builder.go:228.50,232.2 1 1
75+
github.com/studiolambda/akumu/builder.go:234.50,238.2 1 1
76+
github.com/studiolambda/akumu/builder.go:240.47,243.61 2 1
77+
github.com/studiolambda/akumu/builder.go:243.61,247.3 1 0
78+
github.com/studiolambda/akumu/builder.go:249.2,251.21 1 1
79+
github.com/studiolambda/akumu/builder.go:254.84,258.2 2 0
80+
github.com/studiolambda/akumu/builder.go:260.64,264.2 2 0
81+
github.com/studiolambda/akumu/builder.go:266.84,268.2 1 1
82+
github.com/studiolambda/akumu/builder.go:270.63,272.2 1 1
83+
github.com/studiolambda/akumu/builder.go:274.47,278.2 2 1
84+
github.com/studiolambda/akumu/builder.go:280.53,281.23 1 1
85+
github.com/studiolambda/akumu/builder.go:281.23,283.3 1 1
86+
github.com/studiolambda/akumu/builder.go:285.2,285.26 1 1
87+
github.com/studiolambda/akumu/builder.go:285.26,286.42 1 1
88+
github.com/studiolambda/akumu/builder.go:286.42,287.33 1 1
89+
github.com/studiolambda/akumu/builder.go:287.33,289.5 1 1
90+
github.com/studiolambda/akumu/builder.go:293.2,293.23 1 1
91+
github.com/studiolambda/akumu/builder.go:293.23,295.3 1 1
92+
github.com/studiolambda/akumu/builder.go:297.2,297.25 1 1
93+
github.com/studiolambda/akumu/builder.go:297.25,299.3 1 0
94+
github.com/studiolambda/akumu/builder.go:301.2,301.22 1 1
95+
github.com/studiolambda/akumu/builder.go:301.22,303.3 1 0
96+
github.com/studiolambda/akumu/builder.go:305.2,305.16 1 1
97+
github.com/studiolambda/akumu/errors.go:22.39,28.2 1 0
98+
github.com/studiolambda/akumu/handler.go:9.111,10.19 1 1
99+
github.com/studiolambda/akumu/handler.go:10.19,16.3 2 1
100+
github.com/studiolambda/akumu/handler.go:18.2,20.26 1 1
101+
github.com/studiolambda/akumu/handler.go:23.88,24.19 1 0
102+
github.com/studiolambda/akumu/handler.go:24.19,28.3 2 0
103+
github.com/studiolambda/akumu/handler.go:30.2,30.49 1 0
104+
github.com/studiolambda/akumu/handler.go:33.92,34.16 1 1
105+
github.com/studiolambda/akumu/handler.go:34.16,37.3 2 0
106+
github.com/studiolambda/akumu/handler.go:39.2,39.42 1 1
107+
github.com/studiolambda/akumu/handler.go:39.42,42.3 2 1
108+
github.com/studiolambda/akumu/handler.go:44.2,44.19 1 1
109+
github.com/studiolambda/akumu/handler.go:44.19,53.3 3 1
110+
github.com/studiolambda/akumu/handler.go:55.2,57.26 1 1
111+
github.com/studiolambda/akumu/handler.go:60.85,62.2 1 1
112+
github.com/studiolambda/akumu/handler.go:64.55,65.82 1 0
113+
github.com/studiolambda/akumu/handler.go:65.82,67.3 1 0
114+
github.com/studiolambda/akumu/handler.go:70.70,72.2 1 0
115+
github.com/studiolambda/akumu/helpers.go:9.52,15.48 4 1
116+
github.com/studiolambda/akumu/helpers.go:15.48,17.3 1 0
117+
github.com/studiolambda/akumu/helpers.go:19.2,19.20 1 1
118+
github.com/studiolambda/akumu/problem.go:38.47,47.2 1 1
119+
github.com/studiolambda/akumu/problem.go:51.62,57.2 2 1
120+
github.com/studiolambda/akumu/problem.go:59.83,61.2 1 1
121+
github.com/studiolambda/akumu/problem.go:63.79,65.2 1 0
122+
github.com/studiolambda/akumu/problem.go:67.80,69.2 1 1
123+
github.com/studiolambda/akumu/problem.go:71.81,73.2 1 1
124+
github.com/studiolambda/akumu/problem.go:75.84,77.2 1 1
125+
github.com/studiolambda/akumu/problem.go:79.85,96.39 3 1
126+
github.com/studiolambda/akumu/problem.go:96.39,97.43 1 1
127+
github.com/studiolambda/akumu/problem.go:97.43,99.4 1 1
128+
github.com/studiolambda/akumu/problem.go:102.2,103.63 1 1
129+
github.com/studiolambda/akumu/problem.go:108.48,114.2 1 1
130+
github.com/studiolambda/akumu/problem.go:120.59,124.2 2 0
131+
github.com/studiolambda/akumu/problem.go:127.60,128.31 1 1
132+
github.com/studiolambda/akumu/problem.go:128.31,132.3 2 1
133+
github.com/studiolambda/akumu/problem.go:134.2,137.16 3 0
134+
github.com/studiolambda/akumu/problem.go:141.52,142.31 1 0
135+
github.com/studiolambda/akumu/problem.go:142.31,144.3 1 0
136+
github.com/studiolambda/akumu/problem.go:146.2,149.16 3 0
137+
github.com/studiolambda/akumu/problem.go:153.39,155.2 1 0
138+
github.com/studiolambda/akumu/problem.go:158.54,167.45 7 1
139+
github.com/studiolambda/akumu/problem.go:167.45,169.3 1 1
140+
github.com/studiolambda/akumu/problem.go:171.2,171.29 1 1
141+
github.com/studiolambda/akumu/problem.go:175.58,178.54 2 1
142+
github.com/studiolambda/akumu/problem.go:178.54,180.3 1 0
143+
github.com/studiolambda/akumu/problem.go:182.2,182.48 1 1
144+
github.com/studiolambda/akumu/problem.go:182.48,184.3 1 1
145+
github.com/studiolambda/akumu/problem.go:186.2,186.50 1 1
146+
github.com/studiolambda/akumu/problem.go:186.50,188.3 1 1
147+
github.com/studiolambda/akumu/problem.go:190.2,190.49 1 1
148+
github.com/studiolambda/akumu/problem.go:190.49,192.3 1 1
149+
github.com/studiolambda/akumu/problem.go:194.2,194.47 1 1
150+
github.com/studiolambda/akumu/problem.go:194.47,196.3 1 1
151+
github.com/studiolambda/akumu/problem.go:198.2,198.46 1 1
152+
github.com/studiolambda/akumu/problem.go:198.46,200.3 1 1
153+
github.com/studiolambda/akumu/problem.go:202.2,210.12 7 1
154+
github.com/studiolambda/akumu/problem.go:213.72,214.43 1 1
155+
github.com/studiolambda/akumu/problem.go:214.43,216.3 1 0
156+
github.com/studiolambda/akumu/problem.go:218.2,218.33 1 1
157+
github.com/studiolambda/akumu/problem.go:221.65,224.24 2 1
158+
github.com/studiolambda/akumu/problem.go:224.24,226.3 1 1
159+
github.com/studiolambda/akumu/problem.go:228.2,228.25 1 1
160+
github.com/studiolambda/akumu/problem.go:228.25,230.3 1 0
161+
github.com/studiolambda/akumu/problem.go:232.2,232.25 1 1
162+
github.com/studiolambda/akumu/problem.go:232.25,234.3 1 1
163+
github.com/studiolambda/akumu/problem.go:236.2,236.28 1 1
164+
github.com/studiolambda/akumu/problem.go:236.28,238.3 1 1
165+
github.com/studiolambda/akumu/problem.go:240.2,240.42 1 1
166+
github.com/studiolambda/akumu/problem.go:240.42,243.3 2 1
167+
github.com/studiolambda/akumu/problem.go:245.2,245.16 1 1
168+
github.com/studiolambda/akumu/problem.go:250.63,254.2 2 1
169+
github.com/studiolambda/akumu/testing.go:8.90,13.2 3 1
170+
github.com/studiolambda/akumu/testing.go:15.92,20.2 3 1
171+
github.com/studiolambda/akumu/testing.go:22.80,24.2 1 1
172+
github.com/studiolambda/akumu/utils.go:5.35,8.24 2 1
173+
github.com/studiolambda/akumu/utils.go:8.24,10.3 1 1
174+
github.com/studiolambda/akumu/utils.go:12.2,12.15 1 1
175+
github.com/studiolambda/akumu/utils/accept.go:20.48,25.57 2 1
176+
github.com/studiolambda/akumu/utils/accept.go:25.57,26.51 1 1
177+
github.com/studiolambda/akumu/utils/accept.go:26.51,29.18 2 1
178+
github.com/studiolambda/akumu/utils/accept.go:29.18,30.13 1 0
179+
github.com/studiolambda/akumu/utils/accept.go:33.4,35.40 2 1
180+
github.com/studiolambda/akumu/utils/accept.go:35.40,36.60 1 1
181+
github.com/studiolambda/akumu/utils/accept.go:36.60,38.6 1 1
182+
github.com/studiolambda/akumu/utils/accept.go:41.4,44.6 1 1
183+
github.com/studiolambda/akumu/utils/accept.go:48.2,48.15 1 1
184+
github.com/studiolambda/akumu/utils/accept.go:51.60,52.37 1 1
185+
github.com/studiolambda/akumu/utils/accept.go:52.37,53.26 1 1
186+
github.com/studiolambda/akumu/utils/accept.go:53.26,55.4 1 1
187+
github.com/studiolambda/akumu/utils/accept.go:58.3,58.36 1 1
188+
github.com/studiolambda/akumu/utils/accept.go:58.36,60.90 1 1
189+
github.com/studiolambda/akumu/utils/accept.go:60.90,62.5 1 0
190+
github.com/studiolambda/akumu/utils/accept.go:66.3,66.41 1 1
191+
github.com/studiolambda/akumu/utils/accept.go:66.41,68.90 1 1
192+
github.com/studiolambda/akumu/utils/accept.go:68.90,70.5 1 1
193+
github.com/studiolambda/akumu/utils/accept.go:74.2,74.28 1 1
194+
github.com/studiolambda/akumu/utils/accept.go:77.49,81.2 2 1
195+
github.com/studiolambda/akumu/utils/accept.go:83.52,84.46 1 0
196+
github.com/studiolambda/akumu/utils/accept.go:84.46,86.3 1 0
197+
github.com/studiolambda/akumu/utils/accept.go:88.2,88.10 1 0
198+
github.com/studiolambda/akumu/utils/accept.go:91.39,94.37 2 1
199+
github.com/studiolambda/akumu/utils/accept.go:94.37,96.3 1 1
200+
github.com/studiolambda/akumu/utils/accept.go:98.2,98.45 1 1
201+
github.com/studiolambda/akumu/utils/accept.go:98.45,100.3 1 1
202+
github.com/studiolambda/akumu/utils/accept.go:102.2,102.13 1 1
203+
github.com/studiolambda/akumu/router/router.go:39.25,46.2 1 1
204+
github.com/studiolambda/akumu/router/router.go:48.66,55.2 1 0
205+
github.com/studiolambda/akumu/router/router.go:57.41,58.26 1 1
206+
github.com/studiolambda/akumu/router/router.go:58.26,60.3 1 0
207+
github.com/studiolambda/akumu/router/router.go:62.2,62.22 1 1
208+
github.com/studiolambda/akumu/router/router.go:65.60,66.48 1 1
209+
github.com/studiolambda/akumu/router/router.go:66.48,68.3 1 0
210+
github.com/studiolambda/akumu/router/router.go:70.2,70.16 1 1
211+
github.com/studiolambda/akumu/router/router.go:73.57,75.2 1 0
212+
github.com/studiolambda/akumu/router/router.go:77.63,79.2 1 1
213+
github.com/studiolambda/akumu/router/router.go:81.64,83.2 1 0
214+
github.com/studiolambda/akumu/router/router.go:85.64,87.2 1 0
215+
github.com/studiolambda/akumu/router/router.go:89.63,91.2 1 0
216+
github.com/studiolambda/akumu/router/router.go:93.65,95.2 1 0
217+
github.com/studiolambda/akumu/router/router.go:97.66,99.2 1 0
218+
github.com/studiolambda/akumu/router/router.go:101.67,103.2 1 0
219+
github.com/studiolambda/akumu/router/router.go:105.67,107.2 1 0
220+
github.com/studiolambda/akumu/router/router.go:109.65,111.2 1 0
221+
github.com/studiolambda/akumu/router/router.go:113.81,115.2 1 1
222+
github.com/studiolambda/akumu/router/router.go:117.60,118.71 1 1
223+
github.com/studiolambda/akumu/router/router.go:118.71,120.3 1 1
224+
github.com/studiolambda/akumu/router/router.go:122.2,122.14 1 0
225+
github.com/studiolambda/akumu/router/router.go:125.56,129.2 2 1
226+
github.com/studiolambda/akumu/router/router.go:131.81,132.71 1 0
227+
github.com/studiolambda/akumu/router/router.go:132.71,134.3 1 0
228+
github.com/studiolambda/akumu/router/router.go:136.2,136.19 1 0
229+
github.com/studiolambda/akumu/router/router.go:139.78,140.71 1 1
230+
github.com/studiolambda/akumu/router/router.go:140.71,141.49 1 1
231+
github.com/studiolambda/akumu/router/router.go:141.49,143.4 1 1
232+
github.com/studiolambda/akumu/router/router.go:146.2,146.19 1 0
233+
github.com/studiolambda/akumu/router/router.go:149.77,151.2 1 1

middleware.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package akumu
2+
3+
import "net/http"
4+
5+
type Middleware = func(http.Handler) http.Handler

middleware/logger.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
"github.com/studiolambda/akumu"
99
)
1010

11-
func Logger(logger *slog.Logger) func(http.Handler) http.Handler {
11+
func Logger(logger *slog.Logger) akumu.Middleware {
1212
return func(handler http.Handler) http.Handler {
1313
return LoggerWith(handler, logger)
1414
}
1515
}
1616

17-
func LoggerDefault() func(http.Handler) http.Handler {
17+
func LoggerDefault() akumu.Middleware {
1818
return func(handler http.Handler) http.Handler {
1919
return LoggerWith(handler, slog.Default())
2020
}

middleware/problems.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/studiolambda/akumu"
88
)
99

10-
func Problems(controls akumu.ProblemControls) func(next http.Handler) http.Handler {
10+
func Problems(controls akumu.ProblemControls) akumu.Middleware {
1111
return func(handler http.Handler) http.Handler {
1212
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
1313
handler.ServeHTTP(writer, request.WithContext(

middleware/recover.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@ var (
1212
ErrUnexpected = errors.New("an unexpected error occurred")
1313
)
1414

15-
func Recover(handler http.Handler) http.Handler {
16-
return RecoverWith(handler, func(value any) error {
17-
switch err := (value).(type) {
18-
case error:
19-
return err
20-
case string:
21-
return errors.New(err)
22-
case fmt.Stringer:
23-
return errors.New(err.String())
24-
}
15+
func Recover() akumu.Middleware {
16+
return func(handler http.Handler) http.Handler {
17+
return RecoverWith(handler, func(value any) error {
18+
switch err := (value).(type) {
19+
case error:
20+
return err
21+
case string:
22+
return errors.New(err)
23+
case fmt.Stringer:
24+
return errors.New(err.String())
25+
}
2526

26-
return ErrUnexpected
27-
})
27+
return ErrUnexpected
28+
})
29+
}
2830
}
2931

3032
func RecoverWith(handler http.Handler, handle func(value any) error) http.Handler {

router.test

5.69 MB
Binary file not shown.

0 commit comments

Comments
 (0)