Skip to content

Commit 4933b00

Browse files
Update Readme docs
1 parent b9e088b commit 4933b00

File tree

2 files changed

+51
-32
lines changed

2 files changed

+51
-32
lines changed

README.md

+50-31
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,56 @@ y.UseCache = false
283283
```
284284

285285

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+
286336
## Performance
287337

288338
On initial benchmarks, the framework seems to perform very well compared with other similar frameworks.
@@ -338,37 +388,6 @@ func main() {
338388

339389
```
340390

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-
372391

373392
## Why another micro-framework?
374393

yarf.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Yarf struct {
3737
// Follow defines a standard http.Handler implementation to follow if no route matches.
3838
Follow http.Handler
3939

40-
// NotFound defines a function interface to execute when a NotFound error is thrown.
40+
// NotFound defines a function interface to execute when a NotFound (404) error is thrown.
4141
NotFound func(c *Context)
4242
}
4343

0 commit comments

Comments
 (0)