Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing context variables #4

Open
Luukdegram opened this issue Jun 29, 2021 · 0 comments
Open

Allow passing context variables #4

Luukdegram opened this issue Jun 29, 2021 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers Must-have
Milestone

Comments

@Luukdegram
Copy link
Owner

Users only have access to a *Response and Request instance.
This means that if they require access to some allocator, database connection, or w/e, the variable must be global. This is very annoying to work with, and also prone to footguns.

The idea is to allow providing a context variable to the server, which is then accessible within the handler.
Using comptime we can ensure the types match.

This would look as follow:

try server.run(
...,
some_variable,
myHandle);

fn myHandle(ctx: @TypeOf(some_variable), resp: *Response, req: Request) !void {
    // access to `some_variable` is possible here.
    // Allows both constants and mutable pointers, depending on what was provided in the `run` function.
}
@Luukdegram Luukdegram added enhancement New feature or request good first issue Good for newcomers Must-have labels Jun 29, 2021
@Luukdegram Luukdegram added this to the 0.1 milestone Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers Must-have
Projects
None yet
Development

No branches or pull requests

1 participant