Skip to content

Commit 93db9ab

Browse files
committed
📝 Add context document
1 parent dad4087 commit 93db9ab

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/context.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Context
3+
nav_order: 4
4+
---
5+
6+
# Context
7+
8+
Vox's `Context` object is a wrapper around the standard `context.Context` from the Go standard library. It provides a way to pass data between middlewares and to control the execution of the middleware chain.
9+
10+
## App
11+
12+
The `App` field is a pointer to the `vox.Application` instance. This can be used to access the application's configuration or other properties.
13+
14+
## Next
15+
16+
The `Next` function is used to call the next middleware in the chain. It's the middleware's responsibility to call the `Next` function. If a middleware does not call `Next`, the execution of the middleware chain will be terminated.
17+
18+
Here is an example of a simple logging middleware that uses the `Context` object to pass data to the next middleware:
19+
20+
```go
21+
func Logger(ctx *vox.Context, req *vox.Request, res *vox.Response) {
22+
start := time.Now()
23+
ctx.Next()
24+
log.Printf("%s %s %v", req.Method, req.URL.Path, time.Since(start))
25+
}
26+
```

0 commit comments

Comments
 (0)