@@ -43,6 +43,41 @@ var routes = []struct {
43
43
{"GET" , "/user/:username" },
44
44
{"PUT" , "/user/:username" },
45
45
{"DELETE" , "/user/:username" },
46
+ {"GET" , "/pet/:petId/medical-history" },
47
+ {"POST" , "/pet/:petId/vaccination" },
48
+ {"GET" , "/store/order/:orderId/tracking" },
49
+ {"PUT" , "/store/order/:orderId/status" },
50
+ {"GET" , "/user/:username/preferences" },
51
+ {"POST" , "/user/:username/address" },
52
+ {"GET" , "/pet/:petId/appointments" },
53
+ {"POST" , "/pet/:petId/appointment" },
54
+ {"PUT" , "/pet/:petId/appointment/:appointmentId" },
55
+ {"DELETE" , "/pet/:petId/appointment/:appointmentId" },
56
+ {"GET" , "/store/products" },
57
+ {"GET" , "/store/product/:productId" },
58
+ {"POST" , "/store/product" },
59
+ {"PUT" , "/store/product/:productId" },
60
+ {"DELETE" , "/store/product/:productId" },
61
+ {"GET" , "/user/:username/orders" },
62
+ {"POST" , "/user/:username/review" },
63
+ {"GET" , "/user/:username/review/:reviewId" },
64
+ {"PUT" , "/user/:username/review/:reviewId" },
65
+ {"DELETE" , "/user/:username/review/:reviewId" },
66
+ {"GET" , "/clinic/:clinicId" },
67
+ {"POST" , "/clinic" },
68
+ {"PUT" , "/clinic/:clinicId" },
69
+ {"DELETE" , "/clinic/:clinicId" },
70
+ {"GET" , "/clinic/:clinicId/staff" },
71
+ {"POST" , "/clinic/:clinicId/staff" },
72
+ {"GET" , "/clinic/:clinicId/staff/:staffId" },
73
+ {"PUT" , "/clinic/:clinicId/staff/:staffId" },
74
+ {"DELETE" , "/clinic/:clinicId/staff/:staffId" },
75
+ {"GET" , "/clinic/:clinicId/appointments" },
76
+ {"POST" , "/clinic/:clinicId/appointment/:appointmentId/reschedule" },
77
+ }
78
+
79
+ var allParams = []string {
80
+ "petId" , "orderId" , "username" , "appointmentId" , "productId" , "reviewId" , "clinicId" , "staffId" ,
46
81
}
47
82
48
83
func setupLambdaMux () * LambdaMux {
@@ -84,13 +119,14 @@ func ginCreateHandler(method, path string) gin.HandlerFunc {
84
119
responseBody := map [string ]interface {}{
85
120
"message" : "Handled " + method + " request for " + path ,
86
121
}
87
- params := c .Params
88
- if len (params ) > 0 {
89
- paramMap := make (map [string ]string )
90
- for _ , param := range params {
91
- paramMap [param .Key ] = param .Value
122
+ params := make (map [string ]string )
123
+ for _ , param := range allParams {
124
+ if value := c .Param (param ); value != "" {
125
+ params [param ] = value
92
126
}
93
- responseBody ["params" ] = paramMap
127
+ }
128
+ if len (params ) > 0 {
129
+ responseBody ["params" ] = params
94
130
}
95
131
c .JSON (200 , responseBody )
96
132
}
@@ -109,7 +145,12 @@ func fiberCreateHandler(method, path string) fiber.Handler {
109
145
responseBody := map [string ]interface {}{
110
146
"message" : "Handled " + method + " request for " + path ,
111
147
}
112
- params := c .AllParams ()
148
+ params := make (map [string ]string )
149
+ for _ , param := range allParams {
150
+ if value := c .Params (param ); value != "" {
151
+ params [param ] = value
152
+ }
153
+ }
113
154
if len (params ) > 0 {
114
155
responseBody ["params" ] = params
115
156
}
@@ -122,7 +163,7 @@ func setupChiRouter() *chi.Mux {
122
163
for _ , route := range routes {
123
164
// Convert :param to {param} for Chi router
124
165
chiPath := route .path
125
- for _ , param := range [] string { "petId" , "orderId" , "username" } {
166
+ for _ , param := range allParams {
126
167
chiPath = strings .Replace (chiPath , ":" + param , "{" + param + "}" , - 1 )
127
168
}
128
169
r .MethodFunc (route .method , chiPath , chiCreateHandler (route .method , route .path ))
@@ -137,10 +178,9 @@ func chiCreateHandler(method, path string) http.HandlerFunc {
137
178
}
138
179
139
180
params := make (map [string ]string )
140
- rctx := chi .RouteContext (r .Context ())
141
- if rctx != nil {
142
- for i , key := range rctx .URLParams .Keys {
143
- params [key ] = rctx .URLParams .Values [i ]
181
+ for _ , param := range allParams {
182
+ if value := chi .URLParam (r , param ); value != "" {
183
+ params [param ] = value
144
184
}
145
185
}
146
186
@@ -198,6 +238,37 @@ var benchmarkRequests = []events.APIGatewayProxyRequest{
198
238
{HTTPMethod : "GET" , Path : "/user/johndoe" , PathParameters : map [string ]string {"username" : "johndoe" }},
199
239
{HTTPMethod : "PUT" , Path : "/user/janedoe" , PathParameters : map [string ]string {"username" : "janedoe" }},
200
240
{HTTPMethod : "DELETE" , Path : "/user/bobsmith" , PathParameters : map [string ]string {"username" : "bobsmith" }},
241
+ {HTTPMethod : "GET" , Path : "/pet/404/medical-history" , PathParameters : map [string ]string {"petId" : "404" }},
242
+ {HTTPMethod : "POST" , Path : "/pet/505/vaccination" , PathParameters : map [string ]string {"petId" : "505" }},
243
+ {HTTPMethod : "GET" , Path : "/store/order/606/tracking" , PathParameters : map [string ]string {"orderId" : "606" }},
244
+ {HTTPMethod : "PUT" , Path : "/store/order/707/status" , PathParameters : map [string ]string {"orderId" : "707" }},
245
+ {HTTPMethod : "GET" , Path : "/user/alicesmith/preferences" , PathParameters : map [string ]string {"username" : "alicesmith" }},
246
+ {HTTPMethod : "POST" , Path : "/user/bobdoe/address" , PathParameters : map [string ]string {"username" : "bobdoe" }},
247
+ {HTTPMethod : "GET" , Path : "/pet/808/appointments" , PathParameters : map [string ]string {"petId" : "808" }},
248
+ {HTTPMethod : "POST" , Path : "/pet/909/appointment" , PathParameters : map [string ]string {"petId" : "909" }},
249
+ {HTTPMethod : "PUT" , Path : "/pet/1010/appointment/2020" , PathParameters : map [string ]string {"petId" : "1010" , "appointmentId" : "2020" }},
250
+ {HTTPMethod : "DELETE" , Path : "/pet/1111/appointment/2121" , PathParameters : map [string ]string {"petId" : "1111" , "appointmentId" : "2121" }},
251
+ {HTTPMethod : "GET" , Path : "/store/products" },
252
+ {HTTPMethod : "GET" , Path : "/store/product/3030" , PathParameters : map [string ]string {"productId" : "3030" }},
253
+ {HTTPMethod : "POST" , Path : "/store/product" },
254
+ {HTTPMethod : "PUT" , Path : "/store/product/4040" , PathParameters : map [string ]string {"productId" : "4040" }},
255
+ {HTTPMethod : "DELETE" , Path : "/store/product/5050" , PathParameters : map [string ]string {"productId" : "5050" }},
256
+ {HTTPMethod : "GET" , Path : "/user/charlielee/orders" , PathParameters : map [string ]string {"username" : "charlielee" }},
257
+ {HTTPMethod : "POST" , Path : "/user/davidwang/review" , PathParameters : map [string ]string {"username" : "davidwang" }},
258
+ {HTTPMethod : "GET" , Path : "/user/evebrown/review/6060" , PathParameters : map [string ]string {"username" : "evebrown" , "reviewId" : "6060" }},
259
+ {HTTPMethod : "PUT" , Path : "/user/frankgreen/review/7070" , PathParameters : map [string ]string {"username" : "frankgreen" , "reviewId" : "7070" }},
260
+ {HTTPMethod : "DELETE" , Path : "/user/gracewu/review/8080" , PathParameters : map [string ]string {"username" : "gracewu" , "reviewId" : "8080" }},
261
+ {HTTPMethod : "GET" , Path : "/clinic/9090" , PathParameters : map [string ]string {"clinicId" : "9090" }},
262
+ {HTTPMethod : "POST" , Path : "/clinic" },
263
+ {HTTPMethod : "PUT" , Path : "/clinic/1212" , PathParameters : map [string ]string {"clinicId" : "1212" }},
264
+ {HTTPMethod : "DELETE" , Path : "/clinic/1313" , PathParameters : map [string ]string {"clinicId" : "1313" }},
265
+ {HTTPMethod : "GET" , Path : "/clinic/1414/staff" , PathParameters : map [string ]string {"clinicId" : "1414" }},
266
+ {HTTPMethod : "POST" , Path : "/clinic/1515/staff" , PathParameters : map [string ]string {"clinicId" : "1515" }},
267
+ {HTTPMethod : "GET" , Path : "/clinic/1616/staff/1717" , PathParameters : map [string ]string {"clinicId" : "1616" , "staffId" : "1717" }},
268
+ {HTTPMethod : "PUT" , Path : "/clinic/1818/staff/1919" , PathParameters : map [string ]string {"clinicId" : "1818" , "staffId" : "1919" }},
269
+ {HTTPMethod : "DELETE" , Path : "/clinic/2020/staff/2121" , PathParameters : map [string ]string {"clinicId" : "2020" , "staffId" : "2121" }},
270
+ {HTTPMethod : "GET" , Path : "/clinic/2222/appointments" , PathParameters : map [string ]string {"clinicId" : "2222" }},
271
+ {HTTPMethod : "POST" , Path : "/clinic/2323/appointment/2424/reschedule" , PathParameters : map [string ]string {"clinicId" : "2323" , "appointmentId" : "2424" }},
201
272
}
202
273
203
274
func assertResponse (b * testing.B , resp events.APIGatewayProxyResponse , req events.APIGatewayProxyRequest ) {
@@ -228,21 +299,20 @@ func BenchmarkLambdaMux(b *testing.B) {
228
299
}
229
300
}
230
301
231
- func BenchmarkAWSLambdaGoAPIProxyWithGin (b * testing.B ) {
232
- r := setupGinRouter ()
233
- adapter := ginadapter .New (r )
302
+ func BenchmarkLmdRouter (b * testing.B ) {
303
+ router := setupLmdRouter ()
234
304
b .ResetTimer ()
235
305
for i := 0 ; i < b .N ; i ++ {
236
306
req := benchmarkRequests [i % len (benchmarkRequests )]
237
- resp , err := adapter . ProxyWithContext (context .Background (), req )
307
+ resp , err := router . Handler (context .Background (), req )
238
308
assert .NoError (b , err )
239
309
assertResponse (b , resp , req )
240
310
}
241
311
}
242
312
243
- func BenchmarkAWSLambdaGoAPIProxyWithFiber (b * testing.B ) {
244
- app := setupFiberRouter ()
245
- adapter := fiberadapter .New (app )
313
+ func BenchmarkAWSLambdaGoAPIProxyWithGin (b * testing.B ) {
314
+ r := setupGinRouter ()
315
+ adapter := ginadapter .New (r )
246
316
b .ResetTimer ()
247
317
for i := 0 ; i < b .N ; i ++ {
248
318
req := benchmarkRequests [i % len (benchmarkRequests )]
@@ -252,12 +322,13 @@ func BenchmarkAWSLambdaGoAPIProxyWithFiber(b *testing.B) {
252
322
}
253
323
}
254
324
255
- func BenchmarkLmdRouter (b * testing.B ) {
256
- router := setupLmdRouter ()
325
+ func BenchmarkAWSLambdaGoAPIProxyWithFiber (b * testing.B ) {
326
+ app := setupFiberRouter ()
327
+ adapter := fiberadapter .New (app )
257
328
b .ResetTimer ()
258
329
for i := 0 ; i < b .N ; i ++ {
259
330
req := benchmarkRequests [i % len (benchmarkRequests )]
260
- resp , err := router . Handler (context .Background (), req )
331
+ resp , err := adapter . ProxyWithContext (context .Background (), req )
261
332
assert .NoError (b , err )
262
333
assertResponse (b , resp , req )
263
334
}
0 commit comments