@@ -283,6 +283,56 @@ y.UseCache = false
283
283
```
284
284
285
285
286
+ ### Chain and extend
287
+
288
+ Just use the Yarf object as any http.Handler on a chain.
289
+ Set another http.Handler on the Yarf.Follow property to be followed in case this Yarf router can't match the request.
290
+
291
+ Here's an example on how to follow the request to a public file server:
292
+
293
+ ``` go
294
+ package main
295
+
296
+ import (
297
+ " github.com/yarf-framework/yarf"
298
+ " net/http"
299
+ )
300
+
301
+ func main () {
302
+ y := yarf.New ()
303
+
304
+ // Add some routes
305
+ y.Add (" /hello/:name" , new (Hello))
306
+
307
+ // ... more routes here
308
+
309
+ // Follow to file server
310
+ y.Follow = http.FileServer (http.Dir (" /var/www/public" ))
311
+
312
+ // Start the server
313
+ y.Start (" :8080" )
314
+ }
315
+ ```
316
+
317
+
318
+ ### Custom NotFound error handler
319
+
320
+ You can handle all 404 errors returned by any resource/middleware during the request flow of a Yarf server.
321
+ To do so, you only have to implement a function with the func(c * yarf.Context) signature and set it to your server's Yarf.NotFound property.
322
+
323
+ ``` go
324
+ y := yarf.New ()
325
+
326
+ // ...
327
+
328
+ y.NotFound = func (c *yarf.Context ) {
329
+ c.Render (" This is a custom Not Found handler" )
330
+ }
331
+
332
+ // ...
333
+ ```
334
+
335
+
286
336
## Performance
287
337
288
338
On initial benchmarks, the framework seems to perform very well compared with other similar frameworks.
@@ -338,37 +388,6 @@ func main() {
338
388
339
389
```
340
390
341
- ## Chain and extend
342
-
343
- Just use the Yarf object as any http.Handler on a chain.
344
- Set another http.Handler on the Yarf.Follow property to be followed in case this Yarf router can't match the request.
345
-
346
- Here's an example on how to follow the request to a public file server:
347
-
348
- ``` go
349
- package main
350
-
351
- import (
352
- " github.com/yarf-framework/yarf"
353
- " net/http"
354
- )
355
-
356
- func main () {
357
- y := yarf.New ()
358
-
359
- // Add some routes
360
- y.Add (" /hello/:name" , new (Hello))
361
-
362
- // ... more routes here
363
-
364
- // Follow to file server
365
- y.Follow = http.FileServer (http.Dir (" /var/www/public" ))
366
-
367
- // Start the server
368
- y.Start (" :8080" )
369
- }
370
- ```
371
-
372
391
373
392
## Why another micro-framework?
374
393
0 commit comments