-
Notifications
You must be signed in to change notification settings - Fork 327
Per-endpoint configuration #109
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4f9bdd5
Add configuration types
tirr-c af5d370
Expose configuration to endpoints
tirr-c 7ecfafe
Make configurations actually configurable
tirr-c 5b54fc6
Use typemap approach for configuration
tirr-c 2e4c928
Add example for configuration
tirr-c ce58d52
Change module organization of configuration
tirr-c e47776f
Add docs for configuration module
tirr-c e5b906d
Add tests for Configuration, fix existing tests
tirr-c f3789d7
Run rustfmt
tirr-c 702a4e6
Change how the configuration is nested
tirr-c 959713d
Add tests for Router with configuration
tirr-c 06cfc45
Add comments to configuration example
tirr-c 5329b01
Change the name of `RequestConext::get_config` to get_config_item
tirr-c 3f1797e
Rename Configuration to Store and move it to configuration module.
bIgBV 2eb5dfc
Add default configuration and configuration builder types
bIgBV c00e87b
Simple useage of app configuration internally
bIgBV c9dd3bb
Use address from confiugration when starting up server
bIgBV b7ced5a
Fix tests
bIgBV 9255d0a
Adress review comments.
bIgBV b8ada8f
Merge pull request #1 from bIgBV/default-configuration
tirr-c 1c80255
Add more documentation for Configuration
tirr-c 5bc825a
Merge remote-tracking branch 'upstream/master' into configuration
tirr-c 85e5eb6
Address clippy lints
tirr-c a3cb7ff
Make naming consistent
tirr-c 73769de
Change name of Store tests
tirr-c 262985a
Add Debug impl for Store
tirr-c e705b58
Add configuration debug example
tirr-c 34486c2
Merge remote-tracking branch 'upstream/master' into configuration
tirr-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#![feature(async_await, futures_api)] | ||
|
||
use futures::future::FutureObj; | ||
use tide::{head::Path, middleware::RequestContext, ExtractConfiguration, Response}; | ||
|
||
/// A type that represents how much value will be added by the `add` handler. | ||
#[derive(Clone, Debug, Default)] | ||
struct IncreaseBy(i32); | ||
|
||
async fn add( | ||
Path(base): Path<i32>, | ||
// `ExtractConfiguration` will extract the configuration item of given type, and provide it as | ||
// `Option<T>`. If it is not set, the inner value will be `None`. | ||
ExtractConfiguration(amount): ExtractConfiguration<IncreaseBy>, | ||
) -> String { | ||
let IncreaseBy(amount) = amount.unwrap_or_default(); | ||
format!("{} plus {} is {}", base, amount, base + amount) | ||
} | ||
|
||
fn debug_store(ctx: RequestContext<()>) -> FutureObj<Response> { | ||
println!("{:#?}", ctx.store()); | ||
ctx.next() | ||
} | ||
|
||
fn main() { | ||
let mut app = tide::App::new(()); | ||
// `App::config` sets the default configuration of the app (that is, a top-level router). | ||
app.config(IncreaseBy(1)); | ||
app.middleware(debug_store); | ||
app.at("add_one/{}").get(add); // `IncreaseBy` is set to 1 | ||
app.at("add_two/{}").get(add).config(IncreaseBy(2)); // `IncreaseBy` is overridden to 2 | ||
|
||
app.serve(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.