Skip to content

Commit

Permalink
add documentation for global locals
Browse files Browse the repository at this point in the history
Signed-off-by: ngn <[email protected]>
  • Loading branch information
ngn13 committed Jan 15, 2025
1 parent f69e254 commit 7d56efa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,12 @@ to a 404 page, you set a custom route for this:
```c
ctorm_app_all(app, all_route);
```

### Global locals
If you want to pass a variable to all the routes and middlewares, you can use global
locals:
```c
ctorm_app_local(app, "config", &config);
```
To access the local from the route or the middleware handler, you can use `REQ_LOCAL` or
`ctorm_req_local`. See the [request documentation](req.md) for more information.
2 changes: 2 additions & 0 deletions docs/req.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,5 @@ you can access the "username" local:
char *username = REQ_LOCAL("username");
// char *username = ctorm_req_local(req, "username", NULL);
```
If you want to pass a variable to all routes/middlewares, you should use global locals. See
the [app documentation](app.md).

0 comments on commit 7d56efa

Please sign in to comment.