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
Extracting the module #3
Conversation
this is branched off of `gen_schema_2`
_but_ there's an issue with `serde` being imported in both libraries. I'd really like to have that not be the case. Other changes... - added the module name to the `Table` trait, could be better for errors and messaging/debugging. - figured out _something_ with forwarding external dependencies with `$crate::Dep` - `run_proxy!` macro can be used as _main_, so that means, (coolly), that we don't need tokio to be included in the user's lib, all the stuff with it not working was just a bad copypasta, and poor error messages before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaning up and refactoring the library.
num-format = "0.4.0" | ||
warp = "0.2" | ||
url = "2.1.1" | ||
reqwest = { version = "0.10", features = ["json"] } | ||
tokio = { version = "0.2", features = ["full"] } | ||
airtable-proxy = { path = "airtable-proxy" } | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We explicitly clean up the dependencies, moving them into the proxy (or whatever happened here).
edition = "2018" | ||
|
||
[dependencies] | ||
num-format = "0.4.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can see that we moved them all here.
use $crate::gen_schema::Table; | ||
use $crate::network::request::*; | ||
use $crate::network::response::One; | ||
use $crate::transform::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using $crate
makes this better to resolve when used as a dependency.
(@inner $namespace:ident) => {{ | ||
// | ||
// make sure we can airtable, yo, that we have the | ||
// right env setup/permissions here. | ||
let ctx = $crate::airtable::FetchCtx::from_env()?; | ||
|
||
// | ||
// get our server port from the environment, default is 3000 | ||
let address: ::std::net::SocketAddr = ::std::env::var("HOST") | ||
.unwrap_or_else(|_| "127.0.0.1:3000".to_string()) | ||
.parse()?; | ||
|
||
// | ||
// make our context async ready | ||
let ctx = $crate::ctx::wrap_ctx(ctx); | ||
|
||
// | ||
// grab the generated router | ||
// | ||
// todo: this should print/log the routes, which means | ||
// that `route` methods should probably return a tuple | ||
// of the `warp::filter` with some `debug` struct that we | ||
// can output here. | ||
let router = $namespace::gen::route(ctx); | ||
|
||
//TODO: LOGGER | ||
println!("will be serving the app on {}", address); | ||
$crate::warp::serve(router).run(address).await; | ||
|
||
Ok(()) | ||
}}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a macro so that it's nice to run.
It's a PR! to do a thing!